【发布时间】:2017-03-22 10:02:49
【问题描述】:
老实说,我不知道为什么 VBA 编译器会因为 GoTo Jump 和 Jump: 而唠叨我。
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
每次我试图运行我的代码时,这个代码 sn-p 似乎都是一个问题。编译器在最底部标记Next,并告诉我有一个"Next without For"。
但是这种编码不应该有效吗?我刚看到here。然而,奇怪的是,那里的编译器似乎并没有强制 B H 将他的跳转点 NextIteration: 移到最左边,而是让它保持在第二个缩进级别,因此 within for-loop,看起来。 (这还重要吗?)
【问题讨论】:
-
将您的 IF 结构更改为 ElseIF,如下面的答案。然后,您可以删除 goto Jump 行并将 goto Outside 替换为
Exit For。