The following will display a message box when you click series or data point.
Thisworkbook module
Private Sub Workbook_Open()
Main
End Sub
Module1 code
Option Explicit
Private m_clsChartEvents As Class1
Sub Main()
Set m_clsChartEvents = New Class1
Set m_clsChartEvents.Cht = Worksheets("Main").ChartObjects(1).Chart
End Sub
Class1 code
Option Explicit
Public WithEvents Cht As Chart
Private Sub Cht_Select(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long)
Dim vntData As Variant
Dim vntXData As Variant
If ElementID = 3 Then
' selected series
If Arg2 = -1 Then
' selected whole series
MsgBox "Selected Series [" & Arg1 & "] " & Cht.SeriesCollection(Arg1).Name, vbInformation, "Series"
Else
' selected data point
vntData = Cht.SeriesCollection(Arg1).Values
vntXData = Cht.SeriesCollection(Arg1).XValues
MsgBox "Selected DataPoint " & Arg2 & " from Series [" & Arg1 & "] " & Cht.SeriesCollection(Arg1).Name & vbLf & _
vntXData(Arg2) & "," & vntData(Arg2), vbInformation, "Series"
End If
End If
End Sub
Bookmarks