我需要在For Next循环中使用VBA If Else语句
我尝试了各种语句排列方式,但是它们都出错了。
Sub TestForIfElse()
Dim Counter As Integer
Dim i As Integer
For i = 1 To 5
Counter = i
If Counter > 3 Then
Exit For
Else
Next i 'ERROR NEXT WITHOUT FOR
End Sub
运行循环,直到满足测试条件为止。
如果未通过测试,请继续
如果满足测试条件,则退出循环。感谢您的帮助。
答案 0 :(得分:2)
这将起作用:
Sub TestForIfElse()
Dim Counter As Integer
Dim i As Integer
For i = 1 To 5
Counter = i
If Counter > 3 Then
Exit For
End If
Next i
End Sub