Graph with variable range

K

kcrad

I'm having trouble graphing data on a worksheet that has variable ranges.
Can anyone spot the problem with this code? The problem is always with
setting a range for the data.

Here are my variables - I know they work just fine.

xaxis = "A" & "51" & ":" & "A" & 51 + xrange - 1
projected = "D" & "51" & ":" & "D" & 51 + xrange - 1
actual = "E" & "51" & ":" & "E" & 51 + xrange - 1

And here is the first bit of the code for the graph.

Charts.Add
ActiveChart.ChartType = xlXYScatterLines
ActiveChart.SeriesCollection(1).XValues = "Sheets(sheetname).Range(xaxis)"
ActiveChart.SeriesCollection(1).Values =
"Sheets(sheetname).Range(projected)"
ActiveChart.SeriesCollection(2).XValues = "Sheets(sheetname).Range(xaxis)"
ActiveChart.SeriesCollection(2).Values = "Sheets(sheetname).Range(actual)"

"sheetname" is the name of each individual worksheet in the file. That
variable is a string that I've populated earlier in the code.

Thanks!
 
J

Jim Thomlinson

You have put quotes around the range definitions so you are just passing text
instead of ranges. Remove the quotes...

ActiveChart.SeriesCollection(1).XValues = Sheets(sheetname).Range(xaxis)
 
K

kcrad

Sometimes I can be such an idiot!!!

Thanks!

Jim Thomlinson said:
You have put quotes around the range definitions so you are just passing text
instead of ranges. Remove the quotes...

ActiveChart.SeriesCollection(1).XValues = Sheets(sheetname).Range(xaxis)
 

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

Similar Threads


Top