我正在尝试为线图 (xlLineMarkers) 设置具有不同不相邻行的几个图表,但我无法弄清楚如何从不同的子图表中移交定义的范围。
代码如下:
Private Sub butChart2_Click()
Dim wbkKPI As Workbook
Set wbkKPI = Workbooks(ThisWorkbook.Name)
Dim rngA As Range, rngB As Range
Set rngA = ThisWorkbook.Worksheets("Test2").Range("A:A")
Set rngB = ThisWorkbook.Worksheets("Test2").Range("D:D")
Call CreateChart2(wbkKPI, rngA, rngB)
End sub
图表创建子项:
Sub CreateChart2(wbkKPI As Workbook, rngA As Range, rngB As Range)
Dim rng As Range
Dim objChart As Object
Set rng = wbkKPI.Worksheets("Test2").Range(rngA,rngB)
Set objChart = wbkKPI.Worksheets("Test2").Shapes.AddChart2(Height:=400, Width:=500)
objChart.Chart.SetSourceData Source:=rng
objChart.Chart.ChartType = xlLineMarkers
End sUb
生成的图表使用 A 至 D 列作为源,而不仅仅是 A 和 D。我哪里做错了?
由于我需要创建 10 个图表,因此我想在数组中设置范围并在调用图表子例程时循环遍历它们。
谢谢