Search
Close this search box.

VBA If Statement


The If...Then statement is a fundamental control flow structure in VBA that allows you to execute specific code blocks based on a given condition.

How it Works:

  1. Condition: The condition is an expression that evaluates to either True or False.
  2. Code Execution: If the condition is True, the code within the Then block is executed. If the condition is False, the code block is skipped.

Syntax:

If condition Then ‘ Code to execute if condition is True End If

Example

				
					Sub CheckNumber()
    Dim number As Integer
    number = 10

        If number > 5 Then
        MsgBox "The number is greater than 5"
    End If
End Sub