If...Then...Else statement conditionally executes a group of statements, depending on the value of an expression.
If condition Then statements [Else elsestatements ]
If condition Then
[ElseIf condition-n Then
[elseifstatements]] . . .
condition: One or more of the following two types of expressions. A numeric or string expression that evaluates to True or False. If condition is Null, condition is treated as False.
An expression of the form Type of objectname Is object type. The object name is any object reference and object typeis any valid object type. The expression is True if object name is of the object type specified by object type; otherwise it is False.
statements: One or more statements separated by colons; executed if condition is True.
condition-n: Same as condition.
elseifstatements: One or more statements executed if the associated condition-n is True.
elsestatements: One or more statements executed if no previous condition or condition-n expression is True.
'If...Then...Else Total = Inputbox("Please enter the total marks in number ") If Total >= 50 Then MsgBox "Pass" Else Msgbox "Fail" End If
'If....ElseIf Total = Inputbox("Please enter the total marks in number") If Total < 50 Then MsgBox "Fail" ElseIf Total >=50 and Total <=60 then Msgbox "Second Class" ElseIf Total >60 and Total <80 then Msgbox "First Class" ElseIf Total >=80 then Msgbox "Distinction" Else Msgbox "Invalid Marks" End If