do loop
The UK's Number 1 for Microsoft Office Training Add this page to your favourites/bookmarksBookmark page
 
View printable version of pagePrintable version
Plus One Google
Customer: Sign in
Delegate: Sign in
Trainer: Log in

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

Do Loop

resolvedResolved · Medium Priority · Version 2003

replyReply Thu 29 Jan 2009, 16:43Delegate Willem said...

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

Do Loop

What is the Do Loop

For upcoming training course dates see: Pricing & availability

replyReply Mon 2 Feb 2009, 10:02 Edited on Mon 2 Feb 2009, 10:03Trainer Carlos said...

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.

 

Please browse our web site to find out more about
excel training program and other Microsoft training courses.

Excel tip:

Enter formulae into multiple cells

If a formula is to be used in a series of cells, select the cells first. Now type in your formula and hold the Ctrl key while you press Enter. This enters the formula in each selected cell.

Just be careful with your absolute and relative cell references.

View all Excel hints and tips


Microsoft Certified Partner Accredited Training Provider: Institute of IT Training Institute of Leadership and Management - Certified Courses Security Seal verified by visa, mastercard securecard