AndyVoClosser
New Member
- Joined
- Oct 30, 2023
- Messages
- 9
- Office Version
- 365
- Platform
- Windows
Anyone can help me with this code. It does not work with If statement. Please. Thank you
VBA Code:
Sub ShowDataChart1()
Dim ws As Worksheet
Dim myChart As ChartObject
Dim ser As Series
Dim selectedPointIndex As Long
' Set the active sheet
Set ws = ActiveSheet
' Assuming the chart is the first chart on the sheet
Set myChart = ws.ChartObjects(1)
' Assuming you want to work with the first series in the chart
Set ser = myChart.Chart.SeriesCollection(1)
' Loop through each point in the series
For selectedPointIndex = 1 To ser.Points.Count
' Check if the current point is selected
If ser.Points(selectedPointIndex).Select Then
' Activate the "Data (4)" sheet
Sheets("Chart Data").Activate
' Select the corresponding range based on selectedPointIndex
Select Case selectedPointIndex
Case 4
Range("D2:F2").Select
Case 5
Range("D6:F6").Select
' Add more cases as needed
End Select
' Exit the loop once a selected point is found
Exit For
End If
Next selectedPointIndex
End Sub
Last edited by a moderator: