Article ID: 124887
Article Last Modified on 10/11/2006
For...Next Do While...Loop or Do...While Loop If...Else...End If While...Wend Select Case...End SelectIn the above list of block types, the word or words preceding the ellipsis (...) begins a block, which is typically followed by one or more lines of macro code. These lines of code would then typically be followed by the word or words following the ellipsis(...), which comprises the end of a block.
Sub BadNestingExample()
If True Then
For x = 1 To 5
End If
Next x
End Sub
Note that the indentation used above is for illustration purposes only. The
macro above may be indented in such a way that the blocks of control
statements appear correct.
If you attempt to run the above macro, you will receive the "For without
Next" error message. The correct form of the code is as follows:
Sub GoodNesting()
If True Then
For x = 1 To 5
Next x
End If
End Sub
Additional query words: 5.00a 5.00c 7.00a XL98 XL97 XL7 XL5 XL
Keywords: kbdtacode kbinfo kbprogramming KB124887