Microsoft Office Tutorials and References
In Depth Information
Controlling Code Execution
Do
ActiveCell = TheDate
TheDate = TheDate + 1
ActiveCell.Offset(1, 0).Activate
Loop Until Month(TheDate) <> Month(Date)
End Sub
The following example was originally presented for the Do While loop but has been rewritten
to use a Do Until loop. The only difference is the line with the Do statement. This example
makes the code a bit clearer because it avoids the negative required in the Do While example.
Sub DoUntilDemo1()
Dim LineCt As Long
Dim LineOfText As String
Open “c:\data\textfile.txt” For Input As #1
LineCt = 0
Do Until EOF(1)
Line Input #1, LineOfText
Range(“A1”).Offset(LineCt, 0) = UCase(LineOfText)
LineCt = LineCt + 1
Loop
Close #1
End Sub
VBA supports yet another type of loop, While Wend . This looping structure is included
primarily for compatibility purposes. I mention it here in case you ever encounter such
a loop. Here’s how the date entry procedure looks when it’s coded to use a While
Wend loop:
Sub EnterDates5()
Dim TheDate As Date
TheDate = DateSerial(Year(Date), Month(Date), 1)
While Month(TheDate) = Month(Date)
ActiveCell = TheDate
TheDate = TheDate + 1
ActiveCell.Offset(1, 0).Activate
Wend
End Sub
 
Search JabSto ::




Custom Search