条件分岐(If文)
Step4

条件分岐

VBAに限らずプログラミングを学習する上での基礎知識です。。

1. IF文

ある条件のときにだけ、特定の処理を実行する

If 条件 Then
    [条件が真のときの処理]
Else
    [条件が偽のときの処理]
End If
2. 複数条件のIF文

条件を3つ以上に分けたいとき

If 条件1 Then
    [条件1が真のときの処理]
ElseIf 条件2 Then
    [条件2が真のときの処理]
Else
    [上記のどれにも当てはまらないときの処理]
End If
3. サンプルコード

📦 点数(60点)で合格・不合格を分ける

Dim score As Integer
score = 75

If score >= 60 Then
    Debug.Print "Pass"
Else
    Debug.Print "Fail"
End If
Pass

📦 成績をランク分けする

Dim score As Integer
score = 92

If score >= 90 Then
    Debug.Print "Aランク"
ElseIf score >= 70 Then
    Debug.Print "Bランク"
Else
    Debug.Print "Cランク"
End If
Aランク

戻る


© 2026 - Blazor 情処の味方

サポーターズ
Thread Light
An unhandled error has occurred. Reload 🗙