Step 1: Add WorkBook_Open()
Dim ChartObjectClass As New Class1
Dim ChartObjectClass2 As New Class2
Private Sub Workbook_open()
Set ChartObjectClass.ChartObject = Worksheets(1).ChartObjects(1).Chart
Set ChartObjectClass2.ChartObject = Worksheets(1).ChartObjects(2).Chart
End Sub
Step 2:
Add Class1, Class2
Code for Class1 & Class 2:
-------------------------------------------------
Option Explicit
Public WithEvents ChartObject As Chart
Private Sub chartObject_mouseUp(ByVal button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
Dim elementID As Long, arg1 As Long, arg2 As Long
Dim myX As Variant, myY As Double
Dim rng As Range
Set rng = Worksheets(1).Range("Q19")
With ActiveChart
' pass x & y , return elementID and args
.GetChartElement x, y, elementID, arg1, arg2
' did we click over a point or a data label ?
If elementID = xlSeries Or elementID = xlDataLabel Then
If arg2 > 0 Then
' extract x value from array of x values
myX = WorksheetFunction.Index(.SeriesCollection(arg1).XValues, arg2)
' extract y value from array of y values
myY = WorksheetFunction.Index(.SeriesCollection(arg1).Values, arg2)
' display message with point information
'MsgBox "Series" & arg1 & arg2 & vbCrLf & "X=" & myX & "Y=" & myY
On Error Resume Next
' acivate the appropriate chart
' thisworkbook.charts("Chart " & myX).select
Sheets("Series " & myX & " Detail").Select
' the myX to refresh the vlookups
rng.Select
rng.Value = myX
On Error GoTo 0
End If
End If
End With
End Sub
----------------------------------------------------------