12.4. Using Do... Loops for Variable Numbers of Repetitions

Do loops give you more flexibility than For loops in that you can test for conditions in them and direct the flow of the procedure accordingly. VBA includes several types of Do loops:

  • Do While... Loop

  • Do... Loop While

  • Do Until... Loop

  • Do... Loop Until

These loops break down into two categories:

  • Loops that test a condition before performing any action. Do While... Loop and Do Until... Loop loops fall into this category.

  • Loops that perform an action before testing a condition. Do...Loop While and Do... Loop Until fall into this category.

The difference between the two types of loop in each category is that each While loop repeats itself while a condition is True (until the condition becomes ...

Get Mastering VBA for Microsoft Office 2007, 2nd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.