Next没有错误 – 这个代码有什么问题?

我假设我的代码在下面有什么问题,因为它给了我下面的错误: 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 

你错过了一个End With

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