Using While Wend to create a loop

The While...Wend loop is similar to Do...Loop, but it uses the simpler (and less flexible) syntax shown in the following code:

While condition [statements] Wend where condition is an expression that results in a True or False value, and statements are any number of VBA statements, all of which execute with each pass through the loop.

The condition is evaluated at the top of the loop. If the condition proves True, all lines within the loop execute (down to the Wend statement), and then the condition at the top of the loop is evaluated again. If the condition proves False, all statements within the loop are ignored, and processing continues at the first line after the Wend statement.

Statements within a While...Wend loop execute repeatedly, just as they do with a Do...Loop, as illustrated in Figure 4-6.

Code execution

Figure 4-6:

Statements inside this loop execute repeatedly.

Any VBA statement or comment Any VBA statement or comment 'Any VBA statement or comment

'Start of a While.. .Wend loop While counter <= 100

'Any VBA statement or comment 'Any VBA statement or comment 'Any VBA statement or comment

Wend

'Any VBA statement or comment 'Any VBA statement or comment 'Any VBA statement or comment

0 0

Post a comment