使用以下命令中的范围绘制图表。
ActiveChart.SetSourceData Source:=Sheets("Data_Alignment").Range("A1:C721,J1:H721")
当使用命令
时,我需要使用范围作为变量ActiveChart.SetSourceData Source:=Sheets("Data_Alignment").Range(rng1)
它给出了错误1004并且没有生成所需的图表。相反,它选择从A到H的所有数据并绘制图表
我的代码是
Sub ChartMain()
Dim b As Double '/ row1
Dim c As Double '/ row2
Dim rng1 As String
c = 721
For b = 1 To 10400 Step 721
Sheets("Sheet1").Select
Let rng1 = "A" & b & ":C" & c & ",J" & b & ":H" & b
TG_Chart rng1
Next b
End Sub
Sub TG_Chart(rng1)
Sheets("Graphs").Select
ActiveSheet.Shapes.AddChart.Select
ActiveChart.Parent.Left = 60
ActiveChart.Parent.Top = 30
ActiveChart.Parent.Height = 150
ActiveChart.Parent.Width = 400
ActiveChart.SetSourceData Source:=Sheets("Sheet1").Range(rng1)
ActiveChart.ChartType = xlLine
ActiveChart.ClearToMatchStyle
ActiveChart.ChartStyle = 236
ActiveChart.SetElement (msoElementPrimaryCategoryAxisNone)
ActiveChart.SetElement (msoElementPrimaryCategoryGridLinesNone)
ActiveChart.SetElement (msoElementLegendTop)
ActiveChart.Legend.Select
Selection.Width = 277.275
Selection.Left = 6.362
Selection.Width = 374.275
b=b+721
End Sub
请帮我纠正我的代码问题