populate chart array

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to fill an array with the charts on a worksheet so that I can loop through each.
i.e
chartArray = Array(Chart1, Cahart2

For each a in chartArra
'do somethin
next

This is ok, however I don't know the chart names and they will change from time to time

So, how do I populate the array with the chartobjects names on the activesheet

John
 
the chartobjects collection finctions like an array, so often you don'
need to create an array, eg:
Sub show_charts()
For Each CC In ActiveSheet.ChartObjects
MsgBox CC.Name
Next
End Sub


if you do need to create an array, try this:
Sub create_chart_array()
Dim chartarray()
n = 0
For Each CC In ActiveSheet.ChartObjects
ReDim Preserve chartarray(n)
chartarray(n) = ActiveSheet.ChartObjects(n + 1).Name
n = 1 + n
Next
End Su
 
John

You don't need to put them into an array. Try the
following

For Each ch In ActiveSheet.ChartObjects
MsgBox ch.Name
Next ch

Tony
 
Back
Top