以下コードは条件を満たした際に、処理を実行する条件分岐のマクロである。
セルD11にはセルD2からD10の合計値が表示されます。
マクロ実行時のセルD11の値は である。

Sub Exam1()
Dim i As Long
For i = 2 To 11
If Cells(i, 1) = "2" Then
If Cells(i, 2) = "Japan" Then Cells(i, 4) = Cells(i, 3) * 2
End If
If Cells(i , 1) = "3" Then
If Cells(i , 2) = "United States" Then Cells(i, 4) = Cells(i, 3) * 3
End If
Next i
End Sub