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

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

Leave a Reply

Your email address will not be published.