简体   繁体   English

如何在VBA中的图表中更改特定系列的源数据

[英]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. 我需要在VBA中更改图表的特定系列的源数据。 I saw the code used in this: How to get the the source data of all the series of a chart in VBA? 我看到了其中使用的代码: 如何在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. 顺便说一句,我正在使用Excel2003。需要有关如何执行此操作的指导。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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