PDA

View Full Version : Pass Chart Data Point number to variable



sswcharlie
04-01-2018, 04:09 PM
Hi
VBA
On a selected point in chart want to put the number only in to a variable.

activepoint.number.? into variable called say pLog

Is there such a thing as an activepoint? Need number only for ID

Thanks

p45cal
04-02-2018, 02:37 AM
Yes, sort of:

Sub blah()
'ActiveSheet.ChartObjects("Chart 1").Chart.FullSeriesCollection(1).Points(2).Select
'the above line not needed if you have already selected the point using the mouse.
Set myPoint = Selection 'this will be a single point.
'Because Help says:"The name is represented using the following format: S< series number >P< point number >" you should be able to get the index:
PointIndex = CLng(Split(myPoint.Name, "P")(1))
Set mySeries = myPoint.Parent 'this will be a single series on the chart.
Set myPoints = mySeries.Points 'this will be a collection of points
'you can now refer to that point either as myPoints(PointIndex):
Set a = myPoints(PointIndex)
'or as mySeries.points(PointIndex):
Set b = mySeries.Points(PointIndex)
End Sub