图表VBA突然收到错误1004?

时间:2018-08-08 02:19:25

标签: excel vba excel-vba

我写了一段以前工作过的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

0 个答案:

没有答案