Microsoft Office Tutorials and References
In Depth Information
Controlling Code Execution
Do While loops can also contain one or more Exit Do statements. When an Exit Do
statement is encountered, the loop ends immediately and control passes to the statement following
the Loop statement.
Do Until loops
The Do Until loop structure is very similar to the Do While structure. The difference is
evident only when the condition is tested. In a Do While loop, the loop executes while the
condition is True ; in a Do Until loop, the loop executes until the condition is True .
Do Until also has two syntaxes:
Do [Until condition]
[instructions]
[Exit Do]
[instructions]
Loop
or
Do
[instructions]
[Exit Do]
[instructions]
Loop [Until condition]
The two examples that follow perform the same action as the Do While date entry examples in
the previous section. The difference in these two procedures is where the condition is evaluated
(at the beginning or the end of the loop).
Sub EnterDates3()
‘ Do Until, with test at beginning
Dim TheDate As Date
TheDate = DateSerial(Year(Date), Month(Date), 1)
Do Until Month(TheDate) <> Month(Date)
ActiveCell = TheDate
TheDate = TheDate + 1
ActiveCell.Offset(1, 0).Activate
Loop
End Sub
Sub EnterDates4()
‘ Do Until, with test at end
Dim TheDate As Date
TheDate = DateSerial(Year(Date), Month(Date), 1)
 
Search JabSto ::




Custom Search