我尝试使用下拉列表(vba)更改图表数据范围。这是我的代码:
Sub SelectTable()
With ActiveSheet.Shapes(Application.Caller).ControlFormat
If ActiveSheet.Shapes(Application.Caller).Name = "Drop Down 2" Then
Worksheets("Comparison").ChartObjects("Chart 8").Chart.SetSourceData Source:= _
Range(.List(.Value) & "[#All]")
Worksheets("Comparison").ChartObjects("Chart 8").Chart.PlotBy = xlRows
End If
End With
End Sub
选择下拉列表时获取运行时错误:' 1004'
。
此外,此VBA不会基于任何数据透视表。它将在仪表板上进行更改。
是的,图表是使用Pivot创建的,但下拉列表是UserForm和数据验证的组合
答案 0 :(得分:0)
我假设您的列表框返回指定范围的字符串
Sub SelectTable()
With ActiveSheet.Shapes(Application.Caller).ControlFormat
If ActiveSheet.Shapes(Application.Caller).Name = "Drop Down 2" Then
Worksheets("Comparison").ChartObjects("Chart 8").Chart.SetSourceData Source:= _
worksheet("sheetName??").Range(.Value & "[#All]")
Worksheets("Comparison").ChartObjects("Chart 8").Chart.PlotBy = xlRows
End If
End With
End Sub