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

do loop

ResolvedVersion 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:

Edit and format multiple worksheets in one operation

To select two or more non-adjacent worksheets, click on the tab of each worksheet, while holding down the [CTRL] key.
To select two or more adjacent worksheets, click on the tab of the first worksheet and then on the tab of the last worksheet, while holding down the [SHIFT] key.
Enter or modify your data and apply the necessary formatting options to the sheet that's displayed

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.