Decisions with IF · About 5 minutes
Turn codes into names with SWITCH
SWITCH looks at one value and swaps it for a matching result. First the value, then pairs: a code, then what to show for it.
=SWITCH( reads as "if B2 is NE show Northeast, if it's MW show Midwest".
Put one extra value on its own at the end and it becomes the default: what to show when no code matches. Without it, an unknown code shows #N/A.
Part of Plus
Free during our founding launch: sign in to unlock this lesson's exercises, the timed practice sets and the rest of Plus. The free lessons stay free, with no account needed.
What SWITCH does
SWITCH looks at one value and swaps it for a matching result, like turning the code S into Small. You give the value, then pairs of "if it's this, show that".
It is handy for codes that need full names: sizes, regions, shift letters. Add one extra value at the end and it becomes the default, shown for any code that isn't on your list.
How to write SWITCH
=SWITCH(
- expression
- The value to look at, like the code in B2.
- value1
- The first code to match, like
"S". It must match exactly. - result1
- What to show when it matches, like
"Small". - default or value2, result2, ...
- More pairs. Excel accepts up to 126. One value left on its own at the end is the default.
SWITCH worked example
A shop labels sizes with codes. In C2 to C5, show the full size, or Ask for any code not on the list.
| A | B | C | |
|---|---|---|---|
| 1 | Item | Code | Size |
| 2 | Tee | S | Small |
| 3 | Cap | M | Medium |
| 4 | Coat | XL | Ask |
| 5 | Sock | L | Large |
=SWITCH( B2, "S", "Small", "M", "Medium", "L", "Large", "Ask")If B2 is S show Small, if M show Medium, if L show Large, and for anything else show Ask. The coat's XL isn't on the list, so it shows Ask.Common SWITCH mistakes
An unknown code shows #N/A
Add a default as the very last value, on its own, like "Ask". Then any code without a match shows that instead.
A test like >=50 never matches
SWITCH only checks for exact matches, so it can't test bands. Use IFS for "50 or more" style tests.
Number codes don't match
Check whether the codes are numbers or text. A 1 typed as text may not match the number 1 in the formula, so write the code the same way the cells hold it.
SWITCH or IFS?
Use SWITCH when you compare one cell against a list of exact values, like codes. You write the cell once, and the pairs stay short.
Use IFS when each result needs its own test, like a range of numbers or a check on different cells. Both are in Excel 2019 and later, Microsoft 365 and Google Sheets.
Questions people ask
How does SWITCH work?
First the value to check, then pairs of a code and its result: =SWITCH(.
How do I set a default in SWITCH?
Put one extra value on its own at the end. It shows when no code matches; without it, you get #N/A.
SWITCH or IFS?
SWITCH compares one value with exact codes. IFS takes any test, like B2>=90, so it suits bands.
Which versions have SWITCH?
Excel 2019 and later, Microsoft 365, Excel for the web, and Google Sheets. In Excel 2016, use nested IF.