Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Range Syntax Excel VBA

Status
Not open for further replies.

JaHarding

Programmer
Sep 9, 2002
2
US
I'm charting in Excel using VBA.

If I use something like:

Code:
ActiveChart.SetSourceData Source:=Worksheets("Sheet2").Range("A1:D10"), PlotBy:=xlColumns

Then it plots.

But if I use something like:

Code:
ActiveChart.SetSourceData Source:=Worksheets("Sheet2").Range(Cells(1, 1), Cells(10, 4)), PlotBy:=xlColumns

Then I get the method 'cells' of object '_global' failed
error message.

I want to use the Range(Cells... syntax so the chart will reflect changes in the numbers of columns, etc.

Is the 2nd syntax no longer valid? (Excel 2000).
 
You need to qualify the reference to Cells. Ex:

ActiveChart.SetSourceData Source:=Worksheets("Sheet2").Range(Worksheets("Sheet2").Cells(1, 1), Worksheets("Sheet2").Cells(10, 4)), PlotBy:=xlColumns
 
Thank you.

I decided to try the .UsedRange approach and this works as long as the spreadsheet is not "contaminated".

Nevertheless, your solution makes sense and I'm sure I'll be applying it elsewhere.

Thanks again.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top