End If Statements
The previously illustrated “Single-line” If statement effectively addresses scenarios where you are testing a single condition. However, as your IF Statements grow more intricate, involving multiple conditions, it becomes imperative to incorporate an “End If” Statement to delineate the conclusion of the conditional logic.
For example, observe the following code:
If Range(“A2”).Value >0 Then
Range(“B2”).Value = “Positive”
End If
Syntax:
If [test_expression] then
[action]
End If
Then End If signifies the end of the if statement.
VBA IF Statement
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 use how to use the If 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 -> Macros
- Now create a Macro and give any suitable name.
- This will open the Editor window where can write the code.