Reputation: 29064
I need to change the sourcedata of a particular series of an chart in VBA. I saw the code used in this: How to get the the source data of all the series of a chart in VBA? and my code looks like this:
For Each objChrt In ActiveSheet.ChartObjects
Set myChart = objChrt.Chart
myFileName = "myChart" & Index
Next
But I am not sure how to change this code:
ActiveChart.SeriesCollection(i).Values = "=Sheet1!R8C" & j & ":R12C" & j
By the way, I am using Excel 2003. Need some guidance on how to do this.
Upvotes: 1
Views: 3562
Reputation: 19727
You can try this:
myChart.SeriesCollection(1).Values = "Sheet1!R2C1:R7C1" ' refers to A2:A7
Above will work provided you already have an existing chart with existing series.
If not, you need to set the source data instead like this:
myChart.SetSourceData Source:=Sheets("Sheet1").Range("A1:A7")
Upvotes: 1