I'm trying to write some code which will let me edit some data based on user-selection by means of double-clicking on the relevant point in an xy chart.
Eventually I need to be able to figure out how to set it up so that if the user double-clicks on a chart point, I can identify in code which cells in the workbook that datapoint came from.
However, I'm just working up the process at the moment and I wanted to check i can at least correctly identify such a point. So I created a chart (on it's own sheet so I have access to chart events without the hassle of withevents etc) and put the following code in the BeforeDouble_Click event of the chart:
As far as I can see this should issue a message showing the x and y values of the point the user double-clicked, but it doesn't. I throws an error on the line:
xval = ActiveChart.SeriesCollection(Arg1).XValues(Arg2)
If I stop the code at this point and examine the values of arg1 and arg2, they correctly show the index numbers of the series and the point I clicked on. From the help, it seems to me that the above code should work. If I put a watch on the seriescollection, it shows that xvalues() and values() are both valid arrays and I can see the values in them, but when I try to select one of those values using arg2, it crashes. What am I doing wrong?
Tony
Eventually I need to be able to figure out how to set it up so that if the user double-clicks on a chart point, I can identify in code which cells in the workbook that datapoint came from.
However, I'm just working up the process at the moment and I wanted to check i can at least correctly identify such a point. So I created a chart (on it's own sheet so I have access to chart events without the hassle of withevents etc) and put the following code in the BeforeDouble_Click event of the chart:
Code:
Private Sub Chart_BeforeDoubleClick(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long, Cancel As Boolean)
Dim xval As Long, yval As Long
If ElementID = xlSeries Then
xval = ActiveChart.SeriesCollection(Arg1).XValues(Arg2)
yval = ActiveChart.SeriesCollection(Arg1).Values(Arg2)
MsgBox "X = " & Str(xval) & Chr(13) & "Y = " & Str(yval)
End If
End Sub
As far as I can see this should issue a message showing the x and y values of the point the user double-clicked, but it doesn't. I throws an error on the line:
xval = ActiveChart.SeriesCollection(Arg1).XValues(Arg2)
If I stop the code at this point and examine the values of arg1 and arg2, they correctly show the index numbers of the series and the point I clicked on. From the help, it seems to me that the above code should work. If I put a watch on the seriescollection, it shows that xvalues() and values() are both valid arrays and I can see the values in them, but when I try to select one of those values using arg2, it crashes. What am I doing wrong?
Tony