简体   繁体   中英

How to change the sourcedata for a particular series in an chart in VBA

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.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM