do loop

Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Do Loop

Do Loop

resolvedResolved · Medium Priority · Version 2003

Willem has attended:
Excel VBA Intro Intermediate course
Excel VBA Intro Intermediate course

Do Loop

What is the Do Loop

Edited on Mon 2 Feb 2009, 10:03

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 courses

 

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
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.


 

Excel tip:

Display Formulas Instead of Results in Excel 2010

By pressing Ctrl ~ once, Excel will display formulas rather than the results of the formulas. Press it again, and the results will appear again.

A much quicker and simpler way of displaying your formulas!

View all Excel hints and tips


Server loaded in 0.07 secs.