How to use If-Else Statement in Excel VBA? Last Updated : 19 Jul, 2021 Comments Improve Suggest changes Like Article Like Report VBA in Excel stands for Visual Basic for Applications which is Microsoft's programming language. To optimize the performance and reduce the time in Excel we need Macros and VBA is the tool used in the backend. In this article, we are going to learn how to use the If Else statement in Excel VBA. Implementation : In the Microsoft Excel tabs, select the Developer Tab. Initially, the Developer Tab may not be available. The Developer Tab can be enabled easily by a two-step process : Right-click on any of the existing tabs at the top of the Excel window.Now select Customize the Ribbon from the pop-down menu.In the Excel Options Box, check the box Developer to enable it and click on OK. Now, the Developer Tab is visible. Now click on the Visual Basic option in the Developer tab and make a new module to write the program using the Select Case statement. Developer -> Visual Basic -> Tools -> MacrosNow create a Macro and give any suitable name. This will open the Editor window where can write the code. IF Statement : The syntax for the If-Else statement in Excel is : If condition/expression Then Code Block for True Else Code Block for False End If Flow Diagram : Example: Suppose a company kept a new policy. Due to COVID-19. The policy is odd and even days physical presence in the office. The employees whose age is an even number will work on Monday and Wednesday and the employees whose age is odd will work on Tuesday and Thursday. Sub Allocate_Employee() 'Declaring the variable age Dim age As Integer 'Asking age from the employee age = InputBox("Please enter your age:") If (age Mod 2) = 0 Then MsgBox "You have to visit office on Monday and Wednesday" Else MsgBox "You have to visit office Tuesday and Thursday" End If End Sub Output 1: If the user enters 24 which will be an even number will result in a TRUE value in IF. So, the block of code inside IF will only work. Enter Age and Click OKOutput Output 2: If the user enters 27 which will be an odd number will result in a FALSE value in IF. So, the block of code inside Else will only work. Some helpful links to get more insights about Macros, VBA in Excel : Record Macros in Excel.How to Create a Macro in Excel? Comment More infoAdvertise with us Next Article How to use If-Else Statement in Excel VBA? rishabhchakrabortygfg Follow Improve Article Tags : Excel ExcelGuide Similar Reads How to use If-Else-If Statement in Excel VBA? In this article, we are going to look into how to use the If Else If statement in Excel VBA using a suitable example. Implementation : In the Microsoft Excel tabs, select the Developer Tab. Initially, the Developer Tab may not be available. The Developer Tab can be enabled easily by a two-step proce 3 min read How to Use Select Case Statement in Excel VBA? VBA in Excel stands for Visual Basic for Applications which is Microsoft's programming language. To optimize the performance and reduce the time in Excel we need Macros and VBA is the tool used in the backend. In this article, we are going to discuss how to use Select Case Statement in Excel VBA. Se 10 min read How to Delete a Module in Excel VBA? Have you ever seen a text file in a notepad or a source code file in visual studio code? These all are just basic files where you can write some code or information. Similarly, we have modules in excel, each module has its code window, where you can write some code and allow it to automate your repe 3 min read How to Use For Next Loop in Excel VBA? If you are familiar with the programming you must have an idea of what a loop is, In computer programming, a loop is a sequence of statements that are repeated until a specific condition is satisfied. In Excel VBA the "For Next" loop is used to go through a block of code a specific number of times. 4 min read How to Use for Each Loop in Excel VBA? A For Each loop is used to execute a statement or a set of statements for each element in an array or collection. Syntax: For Each element In group [ statements ] [ Exit For ] [ statements ] Next [ element ] The For...Each...Next statement syntax has the following three parts: PartDescriptionelement 3 min read How to Set Variable to Cell Value in Excel VBA? Adding data to the worksheet is often done and it is essential to learn how to set variable to cell value in excel VBA. There can be instances when you want to add the same data to your worksheet. This task could easily be achieved with the help of Excel VBA variables. You can assign your cell value 5 min read How to Use the VBA Immediate Window in Excel? The immediate window is similar to the console in Chrome, where we could execute the javascript. The immediate window allows us to execute macro code very fast and efficiently. Once, you learned it, you will always be found using it. Your immediate window can answer an infinite number of questions, 5 min read How to Use Solver in Excel? A solver is a mathematical tool present in MS-Excel that is used to perform calculations by working under some constraints/conditions and then calculates the solution for the problem. It works on the objective cell by changing the variable cells any by using sum constraints. Solver is present in MS- 3 min read How to use the IFS function in Excel The IFS function in Excel acts as a keen partner, making choices for your information. It's perfect when you have different rules and wish to grant prizes based on those rules. Rather than getting misplaced in complicated enlightening, IFS assists your information in getting to where it ought to go. 7 min read How to Insert and Run VBA Code in Excel? In Excel VBA stands for (Visual Basic for Application Code) where we can automate our task with help of codes and codes that will manipulate(like inserting, creating, or deleting a row, column, or graph) the data in a worksheet or workbook. With the help of VBA, we can also automate the task in exce 2 min read Like