Excel VBA Decisions in Office 365 ~ Easy Tutorial for You!!
Tags: vbamacros, vbadecisionsinexcel
Published: 2020-12-21 04:00:03

---
title: Excel VBA Decisions in Office 365 ~ Easy Tutorial for You!!
published: true
date: 2020-12-19 12:30:59 UTC
tags: VBAMacros,VBADecisionsinExcel
canonical_url: https://geekexcel.com/excel-vba-decisions-in-office-365-easy-tutorial-for-you/
---

As we know that decision-making is the process of  **making**   **choices** by identifying a decision or gathering information and evaluate alternative resolutions. Decision-making allows you to control the execution flow of a program. Excel [VBA](https://geekexcel.com/excel-office-365-vba-overview-definition-and-examples/) provides many decision-making statements, here we are going to see the two most useful conditional statements such as **If …Then…Else ** and **Select Case ** with examples.
## If…Then…Else Statement:

It will test a condition and if the condition is true, it will execute the code. If the condition is false, then the different conditional code is executed.

### Syntax:

**If** condition1 **Then**

**Condition1 code** (When the Condition1 is **True,** it will be executed)

**ElseIf** Condition2 **Then**

**Condition2 code** (When the Condition2 is **True,** it will be executed)

**Else**

**Code** (if the above conditions are **False,** it will be executed)

**End If**

### **Example:**

let us assume the value of a cell is “ **Geek Excel** ” and then **set** the **font size to 50** or **set** the **font size to 10**.

- You need to [**open** the **Visual Basic Editor**](https://geekexcel.com/shortcut-to-open-vba-editor-in-microsoft-excel-365/) by clicking the shortcut [**ALT** + **F11**](https://geekexcel.com/shortcut-to-open-vba-editor-in-microsoft-excel-365/) Keys.
- Then, on the **Insert Tab, select** the **Module** option from the menu.

![Insert Tab](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Insert-Tab-20.png)<figcaption id="caption-attachment-19831">Insert Tab</figcaption>

- Then, you need to **enter the below given VBA code** in the code window.

VBA Code for Example 1

Sub ifStatementEx1()  
If ActiveCell.Value = “Geek Excel” Then  
ActiveCell.Font.Size = 50  
Else  
ActiveCell.Font.Size = 10  
End If  
End Sub

- Finally, you need to **save the code.**

![Save the Code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Save-the-Code-2.png)<figcaption id="caption-attachment-20074">Save the Code</figcaption>

- Now, you need to **close** this **window.**
- Then, go back to the workbook and **run** the **macro** by **clicking** the **Macros** option under the **Developer Tab.**

![Click Macros option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Click-Macros-option.png)<figcaption id="caption-attachment-19833">Click Macros option</figcaption>

- Then, it will display the **Macro Dialog Box** , where you need to **select** the **macro name** and **hit** the **Run** button.

![Macro Dialog Box](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Macro-Dialog-Box-1.png)<figcaption id="caption-attachment-20076">Macro Dialog Box</figcaption>

- Then, it will display the output as shown in the below screenshot.

![Output](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Output-22.png)<figcaption id="caption-attachment-20077">Output</figcaption>

## Select Case Statement:

It is similar to the **If … Then … Else** statement. Select Case statement will check expression or variable if it matches the case statement values, then the code will be executed.

### Syntax:

**Select Case**  Expression

**Case**  Value1

Case statement code1 (If expression equal to value1, it will be executed)

**Case**  Value2

Case statement code2 (If expression is equal to value2, this case will execute)

….

**Case Else**

Case statement else(If none of the values matches the expression, this case will be executed)

### Example 2:

- First, you need to **open** the **Visual Basic Editor** by clicking the shortcut [**ALT** + **F11**](https://geekexcel.com/shortcut-to-open-vba-editor-in-microsoft-excel-365/) Keys.
- Then, on the **Insert Tab, select** the **Module** option from the menu.

![Insert Tab](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Insert-Tab-20.png)<figcaption id="caption-attachment-19831">Insert Tab</figcaption>

- Then, you need to **enter the below given VBA code** in the code window.

VBA code for Select Case Statement

Sub mySelectCaseEx2()  
Dim Sales As Integer  
mySales = ActiveCell.Value  
Select Case Sales  
Case Is < 0  
cRate = 0  
Case Is <= 50  
cRate = 0.5  
Case Is <= 200  
cRate = 0.1  
Case Else  
cRate = 0.2  
End Select  
MsgBox “cRate is” & cRate  
End Sub

- Finally, you need to **save the code.**

![Enter the code](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/1-28.png)<figcaption id="caption-attachment-20078">Enter the code</figcaption>

- Now, you need to **close** this **window.**
- Then, go back to the workbook and **run** the **macro** by **clicking** the **Macros** option under the **Developer Tab.**

![Click Macros option](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/Click-Macros-option.png)<figcaption id="caption-attachment-19833">Click Macros option</figcaption>

- Then, it will display the **Macro Dialog Box** , where you need to **select** the **macro name** and **hit** the **Run** button.

![Click Run button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/2-18.png)<figcaption id="caption-attachment-20079">Click the Run button</figcaption>

- Then, it will display the message box as shown in the below screenshot.

![Click OK button](https://eadn-wc04-371788.nxedge.io/cdn/wp-content/uploads/2020/12/3-16.png)<figcaption id="caption-attachment-20080">Click OK button</figcaption>

## Closure:

In the above article, we helped you to learn the two most useful conditional statements such as **If …Then…Else ** and **Select Case ** with examples. We assisted you to know the **VBA Decisions in Excel Office 365**. If you have any **queries/suggestions,** kindly leave them in the below comment section. Thanks for visiting **[Geek Excel.](https://geekexcel.com/)** Keep Learning!