我真的不知道为什么VBA编译器唠叨我,因为GoTo Jump
,分别Jump:
。Excel VBA:在for循环中跳转:“Next without For” - 我做错了什么?
counter2 = 0
If (counter1 > 1) Then
For i = 0 To (MaxLastCell - 4)
If (IncompleteRows(i) = 1) Then
If ((counter2 > 1) And (counter2 < counter1)) Then
x = x + ", " + CLng(i)
counter2 = counter2 + 1
GoTo Jump
End If
If ((counter2 > 1) And (counter2 = counter1)) Then
x = x + " and " + CLng(i)
GoTo Outside
If (counter2 = 0) Then
x = CLng(i)
counter2 = 1
End If
End If
Jump:
Next i
每当我尝试运行我的代码时,此代码段似乎是一个问题。编译器在最下方标记Next
,并告诉我有一个"Next without For"
。
但不应该这种编码工作?我刚看到它here。然而,一个奇怪的事情是,编译器似乎并没有强制B H将其跳跃点NextIteration:
移动到最左边,但允许它停留在第二个缩进级别,因此在之内for
-loop,as它似乎。 (难道,即使有关系吗?)
将IF结构更改为ElseIF,如下面的答案。然后,您可以删除goto Jump行,并用'Exit For'替换外部的goto。 –