VBA Do While loop in Excel
Do While loop is similar to For loop except that the increment is defined within the loop.
The script within the loop executes as long as the condition specified in the Do While statement is true.
This loop always end with "Loop" keyword.
- Do While
- /code for what should be done here
Example: The following code executes as long as Integer variable "I" is less than 5.
- Sub While_demo()
- Dim i As Integer
- Dim j(5) As Integer
- Do While i <= 5
- j(i) = i
- MsgBox j(i)
- i = i + 1
- End Sub
A glance at the editorial screenshot is shown below.