View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Array of Charts in Excel

You could declare an array of charts but if it's only for the aid of
creating charts I can't see what purpose it serves, unless you need to go
back over them for some reason. It's not clear what you are doing but
whatever it is maybe the following VBA macro will give you some ideas. (Most
of the code is from another post, adapted to include the chart arrray).

Sub test()
Dim j As Long, k As Long, idx as long
Dim chtObj As ChartObject
Dim cht As Chart
Dim sr As Series
Dim arrCharts() As Chart

For k = 2 To 2 + (5 * 3) Step 5
For j = 2 To 2 + (10 * 4) Step 10
idx = idx + 1
Next
Next
ReDim arrCharts(1 To idx) As Chart

idx = 0

For k = 2 To 2 + (5 * 3) Step 5
For j = 2 To 2 + (10 * 4) Step 10
Set rng = Range(Cells(j, k), Cells(j + 7, k + 3))

With rng
Set chtObj = ActiveSheet.ChartObjects.Add(.Left, .Top,
..Width, .Height)
End With

Set cht = chtObj.Chart

' your own code to set source data here in the loop

Set sr = cht.SeriesCollection.NewSeries
sr.Values = "{1,2,3}"

idx = idx + 1
Set arrCharts(idx) = cht

Next
Next

For i = 1 To idx
Debug.Print arrCharts(i).Name
Next

End Sub

Regards,
Peter T

"MD" wrote in message
...
I am trying to program Excel 2007 with VB.NET in order to plot 100 graphs

in
one worksheet. I would like to know if there is any way to declare the

graphs
as an array, like:

Dim MyPlots(99) as Chart

If so, how can I focus in each individual graph and add it to the

worksheet ?

Thanks.

MD