Use Do Until with if statement : Do Until « Language Basics « VBA / Excel / Access / Word






Use Do Until with if statement

 
Sub doTest1()
    Dim intCounter As Integer
    Dim intTest As Integer

    intTest = 1
    intCounter = 1

    Do Until intTest <> 1
        Debug.Print "This is loop number " & intCounter

        If intCounter >= 5 Then
            intTest = 0
        End If

        intCounter = intCounter + 1
    Loop
End Sub

 








Related examples in the same category

1.Do Loop Until
2.Using the Do...Until Loop
3.Exit Do Until Loop
4.Using the Do...Until Loop with a Condition at the Bottom of the Loop