Понедельник, Май 25, 2020

Циклы Do Until

'Do [Until условие]
'   [инструкции]
'   [Exit Do]
'   [инструкции]
'Loop
'или
'Do
'   [инструкции]
'   [Exit Do]
'   [инструкции]
'Loop [Until условие]
Sub EnterDates3()
'1 Цикл Do Until, проверка условия в начале
   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 EnterDates3()
'1 Цикл Do Until, проверка условия в конце
   Dim TheDate As Date
   TheDate = DateSerial(Year(Date), Month(Date), 1)
   Do
      ActiveCell = TheDate
      TheDate = TheDate + 1
      ActiveCell.Offset(1, 0).Activate
   Loop Until Month(TheDate) <> Month(Date)
End Sub


 

Sub DoUntilDemo1()
   Dim LineCt As Long
   Dim LineOfText As String
   Open "c:\text.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


 

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


Back to Top