I've tried multiple approaches, but can't get to make it work.
I need to loop through all the sheets and change the name of the 1st graph.
Here's the code (Type mismatch error):
Sub Change_Chart_Name()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
Sheets(ws).Activate
ActiveSheet.ChartObjects(1).Name = "test2"
Next ws
End Sub
Maybe I could go different way into this? I dont really know, I am a begginer.
CodePudding user response:
Change
Sheets(ws).Activate
with
ws.Activate
CodePudding user response:
Thank to all of you! Its working now, although I needed to combine your advices a bit. Final Code looks like this:
Sub Change_Chart_Name()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
ws.Activate
If ws.ChartObjects.Count > 0 Then
ActiveSheet.ChartObjects(1).Name = "Chart 1"
ActiveSheet.ChartObjects(2).Name = "Chart 2"
ActiveSheet.ChartObjects(3).Name = "Chart 3"
End If
Next ws
End Sub