我想创建一个代码,该代码可以基于动态变化的数据范围创建图表。 (范围内的数据不会更改,但范围选择会更改)。有没有办法为变化的范围引入变量,然后将该变量用作图表的数据源?
Range("D2").Select
Selection.FormulaR1C1 = "=RC[-1]*0.9"
Selection.Copy
ActiveCell.Offset(0, -1).Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 1).Range("A1").Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.End(xlUp).Select
Selection.End(xlDown).Select
Range(Selection, Selection.End(xlUp)).Select
ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("Sheet1!$D$2:$D$4")
Range(Selection,Selection.End(xlUp))。Select-我希望此选定范围用作ActiveChart.SetSourceData中的源:= Range(“ Sheet1!$ D $ 2:$ D $ 4 “)