vba - 如何在Excel VBA中为图表选择多个范围?

标签 vba excel

我想在 Excel 中使用多个范围作为图表。

但我收到以下错误。

Setsourcedata 上的“对象不支持此属性或方法”。

file = ListBox3.ListCount
var = ListBox2.ListCount

Set range1 = Range(Sheets("Vergleich").Cells(27, 1), Sheets("Vergleich").Cells(27 + var, 1))
Set range2 = Range(Sheets("Vergleich").Cells(27, 3), Sheets("Vergleich").Cells(27 + var, 3 + file))

Set range3 = Union(range1, range2)

With Sheets("Vergleich").ChartObjects("Diagramm 4").Activate
    .SetSourceData Source:=ThisWorkbook.Range(range3)
    .PlotBy = xlRows
End With

提前致谢!!

最佳答案

你能试试这个吗?激活存在问题,源范围已定义为代码中的范围。

file = ListBox3.ListCount
Var = ListBox2.ListCount

With Sheets("Vergleich")
    Set range1 = .Range(.Cells(27, 1), .Cells(27 + Var, 1))
    Set range2 = .Range(.Cells(27, 3), .Cells(27 + Var, 3 + file))
    Set range3 = Union(range1, range2)
    .ChartObjects("Diagramm 4").Chart.SetSourceData Source:=range3, PlotBy:= xlRows
End With

关于vba - 如何在Excel VBA中为图表选择多个范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45233332/

相关文章:

excel - 运行时错误 1004 Excel 2013

excel - 在 97-2003 工作表上打开特定的工作表 Excel

c# - 在 Excel 中根据提示删除工作表

vba - 使用模糊匹配动态创建数据透视表

excel - 使用 VBA 取消隐藏 Excel 中的行

Excel - 测试范围地址中的两个连续数字是否相同

c# - 可存储在 Excel 中的值

Java Struts 报告

python - 从 python 运行 excel 宏

excel - 使用单元构建范围