Problems when trying to change source data for pie chart

Pepen123

New Member
Joined
Mar 16, 2012
Messages
6
Hi

I have a sheet (excel 2007), where I would like to copy an entire section of the sheet and paste it further down. This section includes a chart, whose sourcedata I would automatically like to change, when running the macro to do the copy/pasting.

If the original data for the Pie chart is in range("B11:C16") and I wish to change this to range("B41:B46"), I would think I could simply do the following:

Charts("ChartName").SetSourceData Source:=Activesheet.Range("B41:C46")

This however gives me an error saying "subscript out of range". Using named ranges will not be necessary (or usefull in this context), I basically just take a section of the worksheet, paste it alittle further down and type in the needed data. Everything but this changing of the source works perfectly, so I am getting alittle frustrated. Hope you can help!

Thanks in advance

Peter
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Does this work for you?

Code:
ChartObjects("ChartName").Chart.SetSourceData Source:=Activesheet.Range("B41:C46")
 
Upvote 0
Does this work for you?

Code:
ChartObjects("ChartName").Chart.SetSourceData Source:=Activesheet.Range("B41:C46")

It certainly seems to do the trick! Thank you very much. My initial approach was just to follow the explanation on msdn, but that was obviousy a mistake :)
 
Upvote 0
I imagine the explanation on MSDN referred to a Chart sheet. If a chart is on a worksheet it's contained in a ChartObject.
 
Upvote 0

Forum statistics

Threads
1,215,578
Messages
6,125,642
Members
449,245
Latest member
PatrickL

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