Set source data issue...

BigDelGooner

Board Regular
Joined
Aug 17, 2009
Messages
197
hi all

I am trying to set the source data range for a chart within VBA because each time the query is run the range will change.

I am using the following code but when it gets to the .setsourcedata line I get an 'application-defined or object-defined' error.

With ActiveChart.Axes(xlValue)
.MinimumScale = Application.WorksheetFunction.Floor(MinScale - 1, 10)
.MaximumScale = Application.WorksheetFunction.Ceiling(MaxScale + 1, 10)
.SetSourceData Source:=Sheets("Report_Indexed").Range(Cells(2, 2), Cells(End_Row, End_Column)), PlotBy:=xlColumns
End With

Any ideas?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try fully qualifying the range

Code:
.SetSourceData Source:=Sheets("Report_Indexed").Range(Sheets("Report_Indexed").Cells(2, 2), Sheets("Report_Indexed").Cells(End_Row, End_Column)), PlotBy:=xlColumns
 
Upvote 0
Try

Code:
With ActiveChart.Axes(xlValue)
    .MinimumScale = Application.WorksheetFunction.Floor(MinScale - 1, 10)
    .MaximumScale = Application.WorksheetFunction.Ceiling(MaxScale + 1, 10)
End With
ActiveChart.SetSourceData Source:=Sheets("Report_Indexed").Range(Sheets("Report_Indexed").Cells(2, 2), Sheets("Report_Indexed").Cells(End_Row, End_Column)), PlotBy:=xlColumns
 
Upvote 0

Forum statistics

Threads
1,217,358
Messages
6,136,093
Members
449,991
Latest member
IslandofBDA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top