For文
For i = m To n
(中身)
Next
if文
If (条件) Then
文
End If
If (条件1) Then
文
ElseIf (条件2) Then
文
Else
文
End If
For文とIf文の使い分け
Private Sub Worksheet_Activate()
Dim i As Integer
For i = 1 To 10
If IsEmpty(Cells(i, 1)) = True Then
ActiveSheet.Tab.Color = RGB(255, 0, 0)
Exit For
Else
ActiveSheet.Tab.Color = RGB(255, 255, 255)
End If
Next
End Sub
Do Until文
Do Until (条件)
文
Loop
--------------------------------------------
Sub 平均が50点以下のセルを赤にする()
Dim no As Long
no = 4
Do Until Cells(no, 4) = ""
If Cells(no, 4).Value < 50 Then
Cells(no, 4).Interior.ColorIndex = 3
End If
If no >= 11 Then
Exit Do
Else
no = no + 1
End If
Loop
End Sub
条件がTrueになるまで実行する。
実行中の処理を途中で抜ける
Exit Do
Exit For
Exit Function
Exit Property
Exit Sub