Do While loop in VBA
Basic Construct
Sub DoWhileLoop() Dim x As Integer x = 1 Do While x <= 3 MsgBox x x = x + 1 Loop End Sub |
Do While loop to initialize a range of cells in Excel
Sub DoWhileLoop() Dim x As Integer x = 1 Do While x <= 5 Cells(x, 1).Value = x x = x + 1 Loop End Sub |
The output in Excel is shown below.
