I'm trying to loop through charts in a specific worksheet and then move them to a new chart sheet at the end of all the sheets with the following code:
Dim ws As Worksheet, co As ChartObject, c As Chart
Set ws = ThisWorkbook.Sheets("nameofSheet")
ws.Activate
For Each co In ws.ChartObjects
Set c = co.Chart
'do stuff with c
Next co
The problem is, this follows the order in which they were created. I built my workbook by slowly adding more "features" here and there over time, so it doesn't make sense to process the charts in the order they were created.
Is there a way to loop through charts on a worksheet according to their location in the sheet? For example, left to right then up to down. I at least need some sort of known order so that I can process the charts properly.
If there isn't one, will simply changing the chart names individually to "Chart 1", "Chart 2", ..., "Chart n" make the above code I used work?
Set co = ws.ChartObjects("Chart " & CStr(k))
in a for loop. It works, but it's a bit more hardcoded than I'd prefer. I'll try what you and the other user suggested. – christophebedard