BuJay
Board Regular
- Joined
- Jun 24, 2020
- Messages
- 75
- Office Version
- 365
- 2019
- 2016
- 2013
- Platform
- Windows
If I have a worksheet with thousands of charts, how can I get VBA to iterate through each one and rename them? For example, if the first 4 charts are currently names Chart 1001, Chart 1222, Chart 3212, and Chart 5, how do I get vba to iterate through them and rename them to Chart 1, Chart 2, Chart 3, Chart 4? I have 5000+ charts in the worksheet, so I need it to select all ChartObjects one at a time without naming referencing their current names in the loop.
VBA Code:
Sub rename_charts()
Dim ws As Worksheet, outputsh As Worksheet, last_cell As Range, oChartObj As Object
'change Sheet4 to appropriate sheet name
Set ws = ThisWorkbook.Sheets("portfolio_charts")
Set outputsh = ThisWorkbook.Sheets("portfolio_charts")
Sheets("portfolio_charts").Activate
outputsh.Range("A:A").ClearContents
If ws.ChartObjects.Count = 0 Then
outputsh.Range("A2") = "No charts found"
Exit Sub
End If
Debug.Print "Charts found: " & ws.ChartObjects.Count
For Each oChartObj In ws.ChartObjects
With oChartObj
'RENAME CHARTS HERE???
End With
Next
End Sub
Last edited by a moderator: