我写了一段以前工作过的VBA代码,但是最近在名称/ xvalue / value上收到错误1004。我正在使用Excel 2010。
Sub LineChartTemp()
Dim i As Integer, j As Integer, k As Integer
' i = series, j = start row, k = end row
ActiveSheet.Shapes.AddChart.Select
ActiveChart.ChartType = xlLine
Dim chart As chart
Set chart = ActiveChart
For i = 1 To 156
j = (i - 1) * 13 + 1 + 1
k = j + 12
' two 1, one for name row, one for the minus 1, 13 is number of data points of each series
chart.SeriesCollection.NewSeries
chart.SeriesCollection(i).Name = "=" & ActiveSheet.Name & "!$A$" & j & ":$C$" & j
chart.SeriesCollection(i).XValues = "=" & ActiveSheet.Name & "!$D$" & j & ":$D$" & k
chart.SeriesCollection(i).Values = "=" & ActiveSheet.Name & "!$E$" & j & ":$E$" & k
Next i
End Sub