接下来没有For Error - 这段代码有什么问题?

时间:2013-08-12 20:18:26

标签: excel vba excel-vba

我认为下面的代码存在问题,因为它给了我以下错误:Compile error: Next without For

我的代码出了什么问题?谢谢! :)

Sub CreateCharts()

    Dim i As Integer
    For i = 3 To 5

        col = Columns(i).Select

        Dim xaxis As Range
        Dim yaxis As Range
        Set yaxis = Range("$" & col & "$152", "$" & col & "$156")
        Set xaxis = Range("$A$152", "$A$156")
        Dim c As Chart
        Set c = ActiveWorkbook.Charts.Add
        Set c = c.Location(Where:=xlLocationAsObject, Name:="Sheet1")
        c.ChartType = xlColumnClustered

        Dim s As Series
        Set s = c.SeriesCollection.NewSeries
        With s
            .Values = yaxis
            .XValues = xaxis

    Next i
End Sub

1 个答案:

答案 0 :(得分:5)

您错过了End With

    With s
        .Values = yaxis
        .XValues = xaxis
    End With ' <====== HERE
Next i