PC Review


Reply
Thread Tools Rate Thread

How to add series to a chart using a macro

 
 
ucanalways@gmail.com
Guest
Posts: n/a
 
      19th Oct 2007
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

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      19th Oct 2007
Straight from VBA help file:

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


"(E-Mail Removed)" 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
>
>

 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      19th Oct 2007
Sorry, I didn't read far enough. Stand by.

"(E-Mail Removed)" 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
>
>

 
Reply With Quote
 
ucanalways@gmail.com
Guest
Posts: n/a
 
      19th Oct 2007
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 <JLGW...@discussions.microsoft.com> wrote:
> Straight from VBA help file:
>
> Charts("chart1").SeriesCollection.Add _
> source:=Worksheets("sheet1").Range("a1:a19")
>
> "ucanalw...@gmail.com" 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



 
Reply With Quote
 
=?Utf-8?B?SkxHV2hpeg==?=
Guest
Posts: n/a
 
      19th Oct 2007
Well, I tried to find something that was directly related to what you are
attempting and did not do very well at it. However, I did find a site that
gives a lot of references for charting and using VBA to do so. Here is the
site address:

http://www.contextures.com/charts.html

"(E-Mail Removed)" 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
>
>

 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      19th Oct 2007
Hi. Are you using Excel 2007?
The last three loops give Rows above 64k.

Sub test()
For i = 238 To 240
j = ((i - 3) * 524) + 46
k = j + 523
Debug.Print j; k
Next
End Sub

123186 123709
123710 124233
124234 124757

If I did this correctly, maybe:

For TopRow = 1618 To 124234 Step 524
BottomRow = Toptow + 523

Your code part:
> "='Sheet1'!R(j)C1:R(k)C1"


Here, j & k are part of a string. Vba doesn't know to replace "j" with the
value j.

Maybe you could work something like this idea into your code:

For r = 1618 To 124234 Step 524
StrAddress = Cells(r, 1).Resize(524, 1).Address(False, False)
' Do Stuff...
Next r


--
Dana DeLouis
Windows XP & Excel 2007


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>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
>



 
Reply With Quote
 
Thulasiram
Guest
Posts: n/a
 
      19th Oct 2007
On Oct 19, 7:19 am, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:
> Well, I tried to find something that was directly related to what you are
> attempting and did not do very well at it. However, I did find a site that
> gives a lot of references for charting and using VBA to do so. Here is the
> site address:
>
> http://www.contextures.com/charts.html
>
> "ucanalw...@gmail.com" 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


Thanks. I fixing most of my part but still facing errors in this part

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"

R(j)C1:R(k)C1 and R(j)C2 declaration are ok?


 
Reply With Quote
 
ucanalways@gmail.com
Guest
Posts: n/a
 
      19th Oct 2007
On Oct 19, 7:51 am, "Dana DeLouis" <ddelo...@bellsouth.net> wrote:
> Hi. Are you using Excel 2007?
> The last three loops give Rows above 64k.
>
> Sub test()
> For i = 238 To 240
> j = ((i - 3) * 524) + 46
> k = j + 523
> Debug.Print j; k
> Next
> End Sub
>
> 123186 123709
> 123710 124233
> 124234 124757
>
> If I did this correctly, maybe:
>
> For TopRow = 1618 To 124234 Step 524
> BottomRow = Toptow + 523
>
> Your code part:
>
> > "='Sheet1'!R(j)C1:R(k)C1"

>
> Here, j & k are part of a string. Vba doesn't know to replace "j" with the
> value j.
>
> Maybe you could work something like this idea into your code:
>
> For r = 1618 To 124234 Step 524
> StrAddress = Cells(r, 1).Resize(524, 1).Address(False, False)
> ' Do Stuff...
> Next r
>
> --
> Dana DeLouis
> Windows XP & Excel 2007
>
> <ucanalw...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
> >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


Dana, I will get it a try.. I appreciate your help.

 
Reply With Quote
 
ucanalways@gmail.com
Guest
Posts: n/a
 
      19th Oct 2007
On Oct 19, 7:51 am, "Dana DeLouis" <ddelo...@bellsouth.net> wrote:
> Hi. Are you using Excel 2007?
> The last three loops give Rows above 64k.
>
> Sub test()
> For i = 238 To 240
> j = ((i - 3) * 524) + 46
> k = j + 523
> Debug.Print j; k
> Next
> End Sub
>
> 123186 123709
> 123710 124233
> 124234 124757
>
> If I did this correctly, maybe:
>
> For TopRow = 1618 To 124234 Step 524
> BottomRow = Toptow + 523
>
> Your code part:
>
> > "='Sheet1'!R(j)C1:R(k)C1"

>
> Here, j & k are part of a string. Vba doesn't know to replace "j" with the
> value j.
>
> Maybe you could work something like this idea into your code:
>
> For r = 1618 To 124234 Step 524
> StrAddress = Cells(r, 1).Resize(524, 1).Address(False, False)
> ' Do Stuff...
> Next r
>
> --
> Dana DeLouis
> Windows XP & Excel 2007
>
> <ucanalw...@gmail.com> wrote in message
>
> news:(E-Mail Removed)...
>
> >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


Dana, with your for loop, how to modify these two lines in the code..
rest seems ok for me.

First line, i have j and k and second line I have j. Please let me
know if will your code fit into mine? Kind of spilliting my hair here!


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"

I think someone else is on the boat.

 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      19th Oct 2007
Hi. Not sure, but does this general idea work?

Sub Demo()
Dim R As Long ' (R)ow
Dim strAddress As String

ActiveSheet.ChartObjects("Chart 1").Activate

For R = 1618 To 124234 Step 524
strAddress = Cells(R, 1).Resize(524, 1).Address(False, False)
ActiveChart.SeriesCollection.Add Range(strAddress)
Next R
End Sub

I think you are asking about putting Labels on the Series Data.
I'm stuck on that myself. Things are harder to read with Excel's 2007 poor
help system.

--
Dana DeLouis
Windows XP & Excel 2007


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> On Oct 19, 7:51 am, "Dana DeLouis" <ddelo...@bellsouth.net> wrote:
>> Hi. Are you using Excel 2007?
>> The last three loops give Rows above 64k.
>>
>> Sub test()
>> For i = 238 To 240
>> j = ((i - 3) * 524) + 46
>> k = j + 523
>> Debug.Print j; k
>> Next
>> End Sub
>>
>> 123186 123709
>> 123710 124233
>> 124234 124757
>>
>> If I did this correctly, maybe:
>>
>> For TopRow = 1618 To 124234 Step 524
>> BottomRow = Toptow + 523
>>
>> Your code part:
>>
>> > "='Sheet1'!R(j)C1:R(k)C1"

>>
>> Here, j & k are part of a string. Vba doesn't know to replace "j" with
>> the
>> value j.
>>
>> Maybe you could work something like this idea into your code:
>>
>> For r = 1618 To 124234 Step 524
>> StrAddress = Cells(r, 1).Resize(524, 1).Address(False, False)
>> ' Do Stuff...
>> Next r
>>
>> --
>> Dana DeLouis
>> Windows XP & Excel 2007
>>
>> <ucanalw...@gmail.com> wrote in message
>>
>> news:(E-Mail Removed)...
>>
>> >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

>
> Dana, with your for loop, how to modify these two lines in the code..
> rest seems ok for me.
>
> First line, i have j and k and second line I have j. Please let me
> know if will your code fit into mine? Kind of spilliting my hair here!
>
>
> 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"
>
> I think someone else is on the boat.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
chart series macro Tony7659 Microsoft Excel Programming 6 28th Jul 2009 06:08 PM
macro to change series xvalues in chart =?Utf-8?B?YWxsaWdhdG9ybWFraQ==?= Microsoft Excel Programming 1 2nd Mar 2007 11:59 PM
Adding data series to chart via macro =?Utf-8?B?SmVzc0s=?= Microsoft Excel Charting 1 1st Mar 2006 11:04 PM
Limiting Chart Series with a Macro Llednar Microsoft Excel Charting 2 21st Sep 2003 01:45 PM
PPT Macro - Change Chart Series Colors mb Microsoft Powerpoint 3 28th Jul 2003 05:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:39 AM.