Reputation: 125
Hello I am trying to loop through all charts in a selected group and am not having much luck. I am still getting up to speed with VBA and would appreciate any help that you have.
Workflow: 1) I have a set of charts that is grouped together into a array/shape range ( I right clicked all and clicked group) 2) I want to loop through all of the chart objects in the shape range and perform a specific line of code
I have tried to write code that does this if the object is selected but I am having an issue where it doesn't loop through a grouped object. My code is below and any help would be appreicated
Sub ChartLooping1()
Dim cht As Excel.Chart
Dim shp As Object
For Each shp In Selection.ShapeRange
If shp.Type = msoChart Then
Set cht = ActiveSheet.ChartObjects(shp.Name).Chart
MsgBox shp.Chart.Name
End If
Next shp
MsgBox "done"
End Sub
Upvotes: 0
Views: 676
Reputation: 370
I don't have really played much with Shapes (I did something with Charts however) adding .GroupItems after Selection.ShapeRange seems to work:
For Each shp In Selection.ShapeRange.GroupItems
Hope this helps :)
Upvotes: 2