VBA If Else within For Next Loop

前端 未结 1 650
说谎
说谎 2021-01-28 14:56

I need a VBA If Else statement within a For Next loop

I have tried various arrangements of the statements, but they all error out.

Sub TestForIfElse()
           


        
1条回答
  •  北恋
    北恋 (楼主)
    2021-01-28 15:14

    This will work:

    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
    

    0 讨论(0)
提交回复
热议问题