Tip:
Highlight text to annotate it
X
In this lesson, the topic of repetitive execution will be introduced.
Perhaps the greatest feature of a computer is its ability to execute many repetitive statements very quickly.
How long would it take a human to add up all the numbers between 100 and 20000?
Although this task is not difficult, it likely would take a human many hours or even days to complete this assignment manually.
A computer program, on the other hand, could finish this task within less than second.
Even if a human could use a mathematical trick to determine the sum quickly, he or she still would be far slower than a computer.
Loop structures are used to execute a set of statements multiple times.
There are two types of loop structures in VBA.
Both may be used to solve the same problem, but each is better suited for different situations.
For loops are more useful when you want to execute a set of statements a known number of times.
Do loops are more useful when you have a test condition that will determine whether or not a set of statements will be repeated.
There are two types of Do loops.
Do While loops will execute a set of statements repeatedly while a test condition is True.
Do Until loops will execute a set of statements repeatedly until a test condition is True.
In the next few lessons, you will be introduced to all the different types of loops.