In this article, we will talk about how to use the If ElseIf Statement in VBA Excel Office 365 by using the formula and user-defined function in VBA. Let’s see them below!! Get an official version of ** MS Excel** from the following link: https://www.microsoft.com/en-in/microsoft-365/excel
If ElseIf in VBA Syntax
If condition1 then
'Code to execute if condition1 is true
ElseIF Condition2 then
'Code to execute if condition2 is true
ElseIF Condition3 then
'Code to execute if condition3 is true
'--
'--
ElseIF ConditionN then
'Code to execute if conditionN is true
{Else}
'Optional Code if none of the condition is matched.
End If Sub
Example: Grade Marks Using VBA If ElseIf Statements
- Firstly, in the Excel Worksheet, you have to go to the Developer Tab.
- Then, you need to ** ** select the Visual Basic option under the Code section.

- Now, you have to copy and paste the code given below.
Function GRADES(marks As Double)
If marks > 80 Then
GRADES = "A"
ElseIf marks > 60 Then
GRADES = "B"
ElseIf marks > 40 Then
GRADES = "C"
Else
GRADES = "F"
End If
End Function
- After that, you need to save the code by selecting it and then close the window.

- Again, you have to go to the Excel Spreadsheet , and click on the Developer Tab.
- Then, you need to choose the Macros option in the Code section.

- Now, the above function first checks if the supplied value is greater than 80.
- Here, the supplied value is 100 , so it is greater than 80.
- Finally, the given condition falls True , then the function returns A and exits the if block.
A Brief Synopsis
Here, we have explained the step-by-step procedure to use the If ElseIf Statement in VBA Excel Office 365. Make use of this. Please share your worthwhile feedback in the below comment section. To learn more, check out our website *Geek Excel!! *
Read Also:
- Excel VBA Decisions in Office 365 ~ Easy Tutorial for You!!
- LOOKUP and SUM the First or All Matched Values in Rows or Columns in Excel
- Formulas to LOOKUP & SUM the 1st or Matched Values in Row or Column
- Simple Shortcut to Move to the Next Control in MS Excel 365!!
- Easy Shortcut to Move to the Previous Control in Excel 365!!
Top comments (0)