Plot Ranges

M

MikeM

I can write

With ActiveChart
.ChartType = xlXYScatterLinesNoMarkers
.SetSourceData Source:=Sheets(1).Range(Cells(1, 1), Cells(15, 2))
End With

but this doesn't work

setrA = Sheets(1).Range(Cells(1, 1), Cells(15, 2))
With ActiveChart
.ChartType = xlXYScatterLinesNoMarkers
.SetSourceData Source:=rA
End With

Can someone explain why? [I don't want just a fix, but an understanding of
plotting procedures.

TIA,
Mike
 
J

JLGWhiz

When you use the With ActiveChart and then tell it the source is in in
Range(Cells.... it does not find Cells with ActiveChart. Although you
thought you qualified the Cells with Worksheets(1), VBA don't acknowledge it.
So in the second case where you first qualified the range by setting it to
Worksheets(1) in a variable before trying to apply it, it does acknowledge
it. I do the same thing repetitively and I should know better.
 
M

MikeM

Actually, the opposite is true. The first version worked but the second didn't.

JLGWhiz said:
When you use the With ActiveChart and then tell it the source is in in
Range(Cells.... it does not find Cells with ActiveChart. Although you
thought you qualified the Cells with Worksheets(1), VBA don't acknowledge it.
So in the second case where you first qualified the range by setting it to
Worksheets(1) in a variable before trying to apply it, it does acknowledge
it. I do the same thing repetitively and I should know better.

MikeM said:
I can write

With ActiveChart
.ChartType = xlXYScatterLinesNoMarkers
.SetSourceData Source:=Sheets(1).Range(Cells(1, 1), Cells(15, 2))
End With

but this doesn't work

setrA = Sheets(1).Range(Cells(1, 1), Cells(15, 2))
With ActiveChart
.ChartType = xlXYScatterLinesNoMarkers
.SetSourceData Source:=rA
End With

Can someone explain why? [I don't want just a fix, but an understanding of
plotting procedures.

TIA,
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