Using Arrays as Data for a Chart Series

M

mphare

According to the Excel 2000 online help, the *Add* method for
-SeriesCollection- can accept either a *Range* of objects or an *Array
of data points.

In my case an Array will be easier to use, so I tried:


Code
-------------------

row = 3
col = 10
Dim myArray(20) as double

for n = 1 to 20
myArray(n) = cells(row, col + n)
next n

myChartObject.Chart.SeriesCollection.add source:= myArra
-------------------


When the *add* executes I get a "Run-Time error 1004: Reference is no
valid" error message

The previous code looked like:


Code
-------------------

row = 3
col = 10

set fCell = cells(row, col + 1)
set lCell = cells(row, col + 20)

myChartObject.Chart.SeriesCollection.add source:= range(fCell, lCell)

-------------------


Which worked fine, it just not versital enough for some convoluted
dis-jointed, non-contigious series I'm trying to put together. Fillin
an array would be much easier.

Any thoughts as to what I'm doing wrong
 
M

mphare

Thanks Tom, that certainly answers my question and provides
work-around I am going to try.


Thanks again
 
J

Jon Peltier

You can add a series using NewSeries, then apply the array directly
without using an intermediate range.

Dim ns as Series
Set ns = ActiveChart.SeriesCollection.NewSeries
With ns
.Values = myArray
.XValues = myOtherArray
.Name = "New Series"
End With

- Jon
 
M

mphare

Hi Jon,

I just saw your reply and will give that a try.
The work-around Microsoft provided had some problems as well.

Thanks,

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top