View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
[email protected] ucanalways@gmail.com is offline
external usenet poster
 
Posts: 115
Default How to add series to a chart using a macro

JLGWhiz, I am unable to succeed in adding series from the code given
by you. I get "Subscript out of range error". Can you help please?

Thanks


On Oct 18, 8:12 pm, JLGWhiz wrote:
Straight from VBA help file:

Charts("chart1").SeriesCollection.Add _
source:=Worksheets("sheet1").Range("a1:a19")

" wrote:
I am getting the following error for executing this code


Unable to get the chart object property of the worksheet class


Please help me solve the problem.


I am trying to add 240 series to a chart. If someone can help to add
10 series then I will tweak the code for 240 series. Please help.


Code:


Dim mySeries As Series
For i = 6 To 240
j = ((i - 3) * 524) + 46
k = j + 523


Set mySeries = Sheets("Sheet1").ChartObjects("Chart1"). _
Chart.SeriesCollection.NewSeries


mySeries.SeriesCollection(i).XValues = "='Sheet1'!R46C3:R569C3"
mySeries.ChartObjects("Chart 1").SeriesCollection(i).Values =
"='Sheet1'!R(j)C1:R(k)C1"
mySeries.ChartObjects("Chart 1").SeriesCollection(i).Name =
"='Sheet1'!R(j)C2"


Next