(Solved) – Custom Chart point DataLabel Position in Excel VBA

  • by

I’m trying to set a DataLabel of a chart point in VBA, and cant find the way to do it.
In the last part of this code I set up the properties of the chart’s point, but I don’t know how to set up a custom position, I attach a picture of the result I’m trying to have:

                    objCht.Chart.SetSourceData Source:=ResBook.Sheets(Right(NombreHoja, 2)).Range("P1:R" & UltFilaGrafico)
                Call AgregarEjeSecundario("Velocidad [km/h]", 3)

                ActiveChart.Axes(xlValue, xlSecondary).Select
                ActiveChart.Axes(xlValue, xlSecondary).MaximumScale = CInt(TargetVelocity)   10
                ActiveChart.Axes(xlValue, xlSecondary).MinimumScale = 0
                ActiveChart.Legend.Position = xlLegendPositionBottom

                'ActiveChart.SeriesCollection(2).Points(50).MarkerStyle = xlDiamond
                With ActiveChart.SeriesCollection(1)
                    '.Points(StopEventRow).MarkerStyle = xlDiamond
                    .Points(StopEventRow).MarkerStyle = xlMarkerStyleTriangle
                    '.Points(StopEventRow).MarkerSize = 10
                    .Points(StopEventRow).MarkerBackgroundColor = RGB(255, 0, 0)    'Rojo
                    .Points(StopEventRow).MarkerForegroundColor = RGB(1, 1, 1)

                    .Points(StopEventRow).HasDataLabel = True
                    .Points(StopEventRow).DataLabel.text = "Detención"
                    '.Points(StopEventRow).ApplyDataLabels Type:=xlValue
                    .Points(StopEventRow).DataLabel.Font.ColorIndex = 3
                    '.Points(StopEventRow).DataLabel.Position = xlLabelPositionCustom
                    '.Points(StopEventRow).ApplyDataLabels Type:=xlShowLabel

                End With

This is what i’m trying to accomplish trought the VBA code.

Here I manually set up the position of the label, I´m trying to get this done by the code

enter image description here

Leave a Reply

Your email address will not be published. Required fields are marked *