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:
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?
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?