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.
Syntax
- Do While
- /code for what should be done here
- Loop
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
- Loop
- End Sub
A glance at the editorial screenshot is shown below.

Result:


You can find similar Excel Questions and Answer hereunder
1) How to do loops in VBA with the for next loop
2) How can I find the last used cell in a Column in VBA?
3) How can I list all files in a folder using VBA?
4) Here some more advanced range objects and what you can do with the range object in VBA
5) How to go through each item of an array, table, sheet with the for each function
6) How can I find the count of records that meet a given condition in my raw data table?
7) How can I filter a table to get all records that have less than a particular value in a specific column?
8) How can I loop through all ActiveX checkboxes in WorkSheet and set them to Unchecked status?
9) How to do a nested loop in VBA or a loop in a loop
10) How to do webscrapping in VBA. Here some basics