How to Write a Case Statement in Google Sheets


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 Google Sheets 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 in Google Sheets.

Example: Case Statement in Google Sheets

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:

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.

We could also use the following formula to simply return the original value from column A if it does not contain any of the specified values in the SWITCH formula:

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

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

Notice that the last value in column B simply returns a value of Z since the last value in column A didn’t contain any of the specified values in the SWITCH formula.

Note: You can find the complete documentation for the SWITCH function in Google Sheets here.

Additional Resources

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

Google Sheets: A Simple Formula for “If Contains”
How to Use ISERROR in Google Sheets

Leave a Reply

Your email address will not be published.