Mrrrr's Forum (VIEW ONLY)
Un forum care ofera solutii pentru unele probleme legate in general de PC. Pe langa solutii, aici puteti gasi si alte lucruri interesante // A forum that offers solutions to some PC related issues. Besides these, here you can find more interesting stuff.
Lista Forumurilor Pe Tematici
Mrrrr's Forum (VIEW ONLY) | Reguli | Inregistrare | Login

POZE MRRRR'S FORUM (VIEW ONLY)

Nu sunteti logat.
Nou pe simpatie:
Bby67
Femeie
19 ani
Bucuresti
cauta Barbat
19 - 70 ani
Mrrrr's Forum (VIEW ONLY) / Tutoriale si Ghiduri Utile // Tutorials and useful guides / [EXCEL] Change Chart Labels Position via VBA Moderat de TRaP, TonyTzu
Autor
Mesaj Pagini: 1
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
The code below moves all labels for 1 series in my chart to a position way above the series, showing leader lines from the series to the labels.


Sub Chart_Labels_Position()

Dim h, x As Double
Dim i, cnt As Integer

With ActiveSheet
   
    h = ActiveChart.PlotArea.Height
    x = h - (8 * h) / 10
    cnt = ActiveChart.FullSeriesCollection(1).DataLabels.Count
   
    For i = 1 To cnt
        ActiveChart.FullSeriesCollection(1).Points(i).DataLabel.Top = x 'or you can write a number, like 35
    Next i

End With
End Sub


Modificat de TRaP (acum 3 ani)


pus acum 3 ani
   
TRaP
Moderator

Inregistrat: acum 6 ani
Postari: 739
After the line with cnt = ... I had to add the following 2 lines in order to center my labels first, then set their positions, so they are right above the data points.

    ActiveChart.FullSeriesCollection(1).DataLabels.Select
    Selection.Position = xlLabelPositionAbove


pus acum 3 ani
   
Mrrrr
AdMiN

Inregistrat: acum 17 ani
Postari: 2186
Modified the code so it takes into account multiple series:


Sub Chart_Labels_Position()

Dim h, x As Double
Dim i, j, cnt As Integer

With ActiveSheet
   
    h = ActiveChart.PlotArea.Height
    x = h - (9 * h) / 10
   
For j = 1 To ActiveChart.SeriesCollection.count

    cnt = ActiveChart.FullSeriesCollection(j).DataLabels.count
    'ActiveChart.FullSeriesCollection(j).DataLabels.Select ' ENABLE IF NEEDED
    'Selection.Position = xlLabelPositionAbove ' ENABLE IF NEEDED
   
    For i = 1 To cnt
        ActiveChart.FullSeriesCollection(j).Points(i).DataLabel.Top = x 'or you can write a number, like 35
    Next i

Next j

End With
End Sub


_______________________________________


pus acum 3 ani
   
Pagini: 1  

Mergi la