简体   繁体   English

Excel 2013 VBA使用动态范围更改图表对象源

[英]Excel 2013 VBA change a chart object source using dynamic range

I am trying to dynamically set a chart object source. 我正在尝试动态设置图表对象源。 The fdc and ldc variables will change over time. fdcldc变量将随时间变化。 I've tried several variations of code; 我尝试了几种代码变体。 my latest attempt being: 我最近的尝试是:

fdc = 26
ldc = 90
ws.ChartObjects("Chart 2").SetSourceData Source:=ws.Range("S" & fdc & ":V" & ldc)

but they all give: 但他们都给:

Run-time error '438': Object doesn't support this property or method. 运行时错误“ 438”:对象不支持此属性或方法。

You're referring to the ChartObject. 您指的是ChartObject。 SetSourceData is a method of the Chart inside the ChartObject . SetSourceDataChartObject内部的Chart的方法。

Try 尝试

fdc = 26
ldc = 90
ws.ChartObjects("Chart 2").Chart.SetSourceData Source:=ws.Range("S" & fdc & ":V" & ldc)

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

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