FOR loop macro

U

ucanalways

Error:
Unable to set the value propoerty of the series class

Please help me fix this error? Thanks

The code I use is

sub chart ()

Charts.Add


ActiveChart.ChartType = xlXYScatter
ActiveChart.SetSourceData
Source:=Sheets("Sheet1").Range("A45:F63000"), PlotBy:= _
xlColumns


For i = 1 To 10
j = ((i - 1) * 524) + 46
k = j + 523


ActiveChart.SeriesCollection.NewSeries
ActiveChart.SeriesCollection(i).XValues = "='Sheet1'!
R46C3:R569C3"
ActiveChart.SeriesCollection(i).Values = "='Sheet1'!R(" & j &
")C1:R(" & k & ")C1" '''''''''''' Error here
ActiveChart.SeriesCollection(i).Name = "=Sheet1'!R(" & j & ")C2"


Next
 
R

Rick Rothstein \(MVP - VB\)

ActiveChart.SeriesCollection(i).XValues = "='Sheet1'!
R46C3:R569C3"
ActiveChart.SeriesCollection(i).Values = "='Sheet1'!R(" & j &
")C1:R(" & k & ")C1" '''''''''''' Error here

I've not worked with charts myself, so this is just a guess... but shouldn't
the .Values in the above line be .XValues (or maybe .YValues) like in the
line above it?

Rick
 
G

George Nicholson

Try taking out the parentheses (if it works, do the same thing on the next
line)

ActiveChart.SeriesCollection(i).Values = "='Sheet1'!R" & j & "C1:R" & k &
"C1"

HTH,
 
U

ucanalways

I've not worked with charts myself, so this is just a guess... but shouldn't
the .Values in the above line be .XValues (or maybe .YValues) like in the
line above it?

Rick

No it is .values

Even the macro recorder returns it as .values and .xvalues

This makes sense because for a X-Y scatter plot if .xvalues are
declared, then .values automatically refer to y ones.
 
U

ucanalways

Try taking out the parentheses (if it works, do the same thing on the next
line)

ActiveChart.SeriesCollection(i).Values = "='Sheet1'!R" & j & "C1:R" & k &
"C1"

HTH,












- Show quoted text -

George, It doesnt work :(
 
C

Cringing Dragon

George was right, you need to remove the parentheses from both lines of code.
But as well as that, in your .Name line, you are missing an apostrophe
between = and Sheet1.
 

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