Public Sub Pf_ForEach()
Dim i As Variant
Dim iDivided As Integer
Dim iRow As Integer
Dim arrI() As Variant
arrI = Array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
For Each i In arrI
' iを3で割った余りを求める
iDivided = i Mod 3
iRow = iRow + 1: Cells(iRow, 1).Value = i & "を3で割った余り:" & iDivided
' iが3以下の時は次ループ
If i <= 3 Then
iRow = iRow + 1: Cells(iRow, 1).Value = "continue"
Else
' 余りが1以外の時はループを抜ける
If iDivided <> 1 Then
iRow = iRow + 1: Cells(iRow, 1).Value = "break"
Exit For
End If
iRow = iRow + 1: Cells(iRow, 1).Value = "ループ"
End If
Next i
End Sub
|