Willem has attended:
Excel VBA Intro Intermediate course
Excel VBA Intro Intermediate course
Do Loop
What is the Do Loop
RE: Do Loop
Hi Willem
There are two types of Do...Loop.
The Do While...Loop and the Do Until...Loop
The Do While...Loop
You can use the Do While ... Loop to test a condition at the start of the loop. It will run the loop as long as the condition is true and stops when the condition becomes false. For Example:
Counter = 1
Do While Counter =< 10
Cells(Counter, 1).Value = Counter
Counter = Counter + 1
Loop
One thing to be caution is that sometimes the loop might be a infinite loop. And it happens when the condition never becomes false. In such case, you can stop the loop by press [ESC] or [CTRL] + [BREAK].
Do Until ... Loop
You can test the condition at the beginning of the loop and then run the loop until the test condition becomes true.
Example:
Counter = 1
Do Until Counter = 11
Cells(Counter, 1).Value = Counter
Counter = Counter + 1
Loop
These looping processes yield the same result as in the For ... Next structures example.
Hope this helps
Carlos

