4.2 C
London
Friday, December 20, 2024
HomeSoftware TutorialsExcelHow to Write a Case Statement in Excel (With Example)

How to Write a Case Statement in Excel (With Example)

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

A case statement is a type of statement that goes through conditions and returns a value when the first condition is met.

The easiest way to implement a case statement in Excel is by using the SWITCH() function, which uses the following basic syntax:

=SWITCH(A2, "G", "Guard", "F", "Forward", "C", "Center", "None")

This particular function looks at cell A2 and returns the following value:

  • Guard” if cell A2 contains “G”
  • Forward” if cell A2 contains “F”
  • Center” if cell A2 contains “C”
  • None” if cell A2 does not contain any of the previous values

The following example shows how to use this function in practice.

Example: Case Statement in Excel

Suppose we have the following list of basketball positions:

We’ll use the following SWITCH() function to return a specific position name in column B based on the value in column A:

=SWITCH(A2, "G", "Guard", "F", "Forward", "C", "Center", "None")

We’ll type this formula into cell B2 and then copy and paste it down to every remaining cell in column B:

case statement in Excel

Notice that this formula returns the following values in column B:

  • Guard” if column A contains “G”
  • Forward” if column A contains “F”
  • Center” if column A contains “C”
  • None” if column A does not contain any of the previous values

Notice that the last value in column B returns a value of “None” since we didn’t specify a specific value to return for “Z” in the formula.

Additional Resources

The following tutorials explain how to perform other common tasks in Excel:

Excel: How to Find Unique Values from Multiple Columns
Excel: How to Match Two Columns and Return a Third

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories