Spreadsheet Practice

How to use SWITCH instead of nested IFs in Excel

Formula (Excel and Google Sheets)

=SWITCH(B2,"N","North","S","South","E","East","W","West","Unknown")

List each value and its result in pairs, with a default at the end: =SWITCH(B2,"N","North","S","South","E","East","W","West","Unknown").

Result on the example
one result per row in C2, filled down to C7
Works in
Excel 2019 and later, including Microsoft 365
Google Sheets
Same formula

See it work

The formula is already in C2, filled down to C7. Change any input and the result updates, or edit the formula to experiment.

How it works

SWITCH compares the first argument with each value in turn and returns the result paired with the first match. The final lone argument is the default, used when nothing matches, as for Fay's "X". The cell is written once instead of once per IF.

=SWITCH(B2,"N","North","S","South","E","East","W","West","Unknown")

Result"North"

  1. B2"N"

    The value in B2.

  2. SWITCH(B2,"N","North","S","South","E","East","W","West","Unknown")"North"

    SWITCH: Matches an expression against a list of values.

    • expressionB2"N"
    • value1"N"
    • result1"North"
    • default"S"
    • value2"South"
    • result2"E"
    • value3"East"
    • result3"W"
    • value4"West"
    • result4"Unknown"

In Google Sheets

The same formula works in Google Sheets: =SWITCH(B2,"N","North","S","South","E","East","W","West","Unknown"). We ran it in Google Sheets mode on the same data and it returns the same results.

Other ways to do it

Each one was run on the same example sheet.

FormulaResultWhen to use it
=IF(B2="N","North",IF(B2="S","South",IF(B2="E","East",IF(B2="W","West","Unknown"))))North, South, East…The nested IF that SWITCH replaces. Works in every version, including Excel 2016.
=XLOOKUP(B2,{"N","S","E","W"},{"North","South","East","West"},"Unknown")North, South, East…A lookup on two array constants. Move them into cells and it becomes a table you can edit.

Common mistakes

  • SWITCH only tests for equality. For ranges like "90 and above" use IFS, or SWITCH(TRUE,B2>=90,"A",B2>=80,"B","C").
  • Without a default, a value that matches nothing returns #N/A.
  • SWITCH needs Excel 2019 or later (or Google Sheets). Excel 2016 shows #NAME?.

Try it yourself

Same data, empty answer cell. Your formula is graded instantly, then re-checked on changed data, so a typed-in number won't pass.

Use SWITCH instead of nested IFs

In C2, turn the region code into its name: N North, S South, E East, W West, and "Unknown" for anything else. Fill down to C7.

Questions

Is SWITCH case-sensitive?

No. "n" matches "N", just as with =.

How many pairs can SWITCH take?

Up to 126 value and result pairs. Long before that, a lookup table is easier to maintain.

Checked by running on 2026-10-30: every formula and result on this page was calculated by the Spreadsheet Practice formula engine, in both Excel and Google Sheets modes.