
- VBA Tutorial
- VBA - Home
- VBA - Overview
- VBA - Excel Macros
- VBA - Excel Terms
- VBA - Macro Comments
- VBA - Message Box
- VBA - Input Box
- VBA - Variables
- VBA - Constants
- VBA - Operators
- VBA - Decisions
- VBA - Loops
- VBA - Strings
- VBA - Date and Time
- VBA - Arrays
- VBA - Functions
- VBA - Sub Procedure
- VBA - Events
- VBA - Error Handling
- VBA - Excel Objects
- VBA - Text Files
- VBA - Programming Charts
- VBA - Userforms
- VBA Useful Resources
- VBA - Quick Guide
- VBA - Useful Resources
- VBA - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
VBA - If-Else Statement
An If statement consists of a Boolean expression followed by one or more statements. If the condition is said to be True, the statements under If condition(s) are executed. If the condition is said to be False, the statements under Else Part is executed.
Syntax
Following is the syntax of an If Else statement in VBScript.
If(boolean_expression) Then Statement 1 ..... ..... Statement n Else Statement 1 ..... .... Statement n End If
Flow Diagram

Example
For demo purpose, let us find the biggest between the two numbers of an Excel with the help of a function.
Private Sub if_demo_Click() Dim x As Integer Dim y As Integer x = 234 y = 324 If x > y Then MsgBox "X is Greater than Y" Else Msgbox "Y is Greater than X" End If End Sub
When the above code is executed, it produces the following result.
Y is Greater than X
vba_decisions.htm
Advertisements