Вторник, Май 26, 2020

Конструкция For Each - Next

'Синтаксис
'For Each элемент In коллекция
'   [инструкции]
'   [Exit For]
'   [инструкции]
'Next [элемент]
Sub CountSheets()
  Dim item As Worksheet
  For Each item In ActiveWorkbook.Worksheets
     MsgBox item.Name
  Next item
End Sub


 

Sub MakeUpperCase()
  Dim cell As Range
  For Each cell In Selection
     cell.Value = UCase(cell.Value)
  Next cell
End Sub



Sub SelectNegative()
  Dim cell As Range
  For Each cell In Range("1:1")
     If cell.Value < 0 Then
        cell.Select
        Exit For
     End If
  Next cell
End Sub


Back to Top