98.7% Of all customers recommend us, we're so confident about our results we publish all reviews and stats
View Live Stats View ReviewsForum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Do Loop
Do Loop
Resolved · Medium Priority · Version 2003
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
Mon 9 Feb 2009: Automatically marked as resolved.
Training information:
Welcome. Please choose your application (eg. Excel) and then post your question. Our Microsoft Qualified trainers will then respond within 24 hours (working days). Frequently Asked Questions
Any suggestions, questions or comments? Please post in the Improve the forum thread. |
Excel tip:Display Formulas Instead of Results in Excel 2010By pressing Ctrl ~ once, Excel will display formulas rather than the results of the formulas. Press it again, and the results will appear again. |