Forum Discussion
Lacra6
Feb 28, 2024Copper Contributor
Chart data labels
Hi, I build a Dashboard (multiple pivot charts in it) and I am looking to make the chart data labels clickable so when I click on them to bring me to the associated data from the original data sheet...
JKPieterse
Feb 29, 2024Silver Contributor
Lacra6 Add this code to the worksheet containing your chart, switch to a different worksheet and back and see what happens when you click a chart. Might want to do this on a copy of your file 🙂
Option Explicit
Private WithEvents cht As Chart
Private Sub cht_Select(ByVal ElementID As Long, ByVal Arg1 As Long, ByVal Arg2 As Long)
MsgBox "Selected element id: " & ElementID & vbNewLine & "Value for Arg 1: " & Arg1 & vbNewLine & "Value for Arg2: " & Arg2
End Sub
Private Sub Worksheet_Activate()
Set cht = Me.ChartObjects(1).Chart
End Sub
Private Sub Worksheet_Deactivate()
Set cht = Nothing
End Sub
If I got it right, elementId=3 are the chart series, arg1 is the series number and arg2 the datapoint number. Experiment!