Conditional Statement If…Then…Else Statement

If…Then…Else Statement

 

Conditionally executes a group of statements, depending on the value of an expression.

 

Syntax Format:

If condition Then [statements] Else [statements]

 

Or, you can use the block form syntax:

 

If condition Then

[Statement]

ElseIf condition Then

[Statement]

ElseIf condition Then

[Statement]

ElseIf condition Then

[Statement]

.  .  .  .  .  .

Else: End If

 

Sub My_IF()

Dim MyNumber, A, B, C

MyNumber = Range(“B2”).Value

A = 1

B = 2

C = 3

If MyNumber < 10 Then A = A + MyNumber: B = B + A: C = C + B

Range(“B2”).Value = C

MsgBox (“Your value is:  ” & C)

End Sub