0

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
Edward Armstrong
  • 105
  • 1
  • 5
  • 18

1 Answers1

2

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 :)

Zenigata
  • 360
  • 1
  • 3
  • 12
  • You're welcome :) Maybe you could take a look [here](http://stackoverflow.com/questions/28840857/excel-2010-vba-and-listobjects-subtotals-not-updating-on-table-changes) – Zenigata Mar 03 '15 at 22:11