Do until loop in excel vba
The Do Until Loop is used when we want to repeat a block of code indefinitely until the condition is True.
The Do Until Loop Statements check the condition at the start of the loop and Do Loop Until Statements check the condition at the end of the loop.
Do Until… loop statements
Syntax 1)
Do Until [condition]
[Block of code or statements]
Loop
For example,
Sub do_untilloop()
i = 5
Do Until i > 10
i = i + 1
MsgBox (“The value of i is : ” & i)
Loop
End Sub
Do… Until loop Statements
Syntax 2)
Do
[Block of code or statements]
Loop Until [condition]
For example,
Sub doloop_until()
i = 5
Do
i = i + 1
MsgBox “the value of i is: ” & i
Loop Until i < 10
End Sub
Sub Do_Until_Example1()
Dim x As Long
x = 1
Do Until x = 11
Cells(x, 1).Value = x
x = x + 1
Loop
End Sub
Sub test()
Dim i As Integer
i = 1
Do Until i > 6
Cells(i, 1).Value = 20
i = i + 1
Loop
End Sub