Macor to update Chart Data Range

rdw72777

Well-known Member
Joined
Apr 5, 2005
Messages
723
I've been spinning my wheels a bit on this one. Bacially, I have a chart in my workbook for which I'd like to update the data range via macro. I searched the site and the code to add a chart was pretty basic so i figured I'd just record the changes I want to make and begin working with that.

This is the code I recorded:

Code:
Sub Macro16()
'
Sheets("sheet1").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SetSourceData Source:=Sheets("sheet2").Range( _
    "A7,A34:A54,C7:H7,C34:H54")
End Sub

I hate the Select/Activate actions as much as anyone, but what I found odd was, even though this is recorded code, if I try to run the macro it doesn't work. On the "Chart 1.Activate" line I get the error "The item with the specified name wasn't found"

The code for adding new charts seems to work, but my existing charts have so much formatting and manual changes (color schemes and etc.) that I would MUCH rather update an existing chart's data range than build one from scratch via code.

I'm wondering if the fact that this is a whole tab chart (i.e. the kind you do when right-clicking on a worksheet tab and selecting Insert-Chart, not the kind tyou insert fromthe Insert menu in the ribbon) has something to do with this.

Any thoughts on why the recorded code doesn't work?
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Actually, when i click the chart on sheet 1 I don't see any name in the named ranges box. I have no idea where "Chart 1" comes from, but the macro records it as "Chart 1". But how do i identify this chart then....
 
Upvote 0
I think I figured out, on these types of Chart Sheets, it looks like you can just eliminate the selection of a chartobject since the whole sheet is a chart object.

thanks,
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,682
Members
452,937
Latest member
Bhg1984

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