Code to label
| A | |
|---|---|
| 1 | Code |
| 2 | W |
Formula: C1: =SWITCH(A2,"E","East","W","West","N","North","Unknown")
Result: West
A2 is compared with each code in turn; the last lone argument is the default.
Picks a result by exact match.
SWITCH(expression, value1, result1, …, [default])Example: =SWITCH(A2,"Boston","East","Denver","Central","Other")
Available in: Excel 2019+
SWITCH compares one expression against a list of values and returns the result for the first match, with an optional default: =SWITCH(expression, value1, result1, …, default). It is cleaner than nested IFs when you test one cell against fixed codes.
| A | |
|---|---|
| 1 | Code |
| 2 | W |
Formula: C1: =SWITCH(A2,"E","East","W","West","N","North","Unknown")
Result: West
A2 is compared with each code in turn; the last lone argument is the default.
| A | |
|---|---|
| 1 | Date |
| 2 | 3/9/2024 |
Formula: C1: =SWITCH(WEEKDAY(A2),1,"Sun",7,"Sat","Weekday")
Result: Sat
WEEKDAY returns 7 for Saturday, so the second pair matches. March 9, 2024 is a Saturday.
| A | |
|---|---|
| 1 | Units |
| 2 | 75 |
Formula: C1: =SWITCH(TRUE,A2<50,"Low",A2<100,"Mid","High")
Result: Mid
Each test returns TRUE or FALSE; SWITCH picks the first one that equals TRUE.
A tiny spreadsheet with example data. Edit the formula or any number and see the result.
Formula in F2: =SWITCH(C2,"Yes","Bonus","No","None","Other")
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Student | Score | Extra credit | Attempts | Result | |
| 2 | Ann | 92 | Yes | 2 | Bonus | |
| 3 | Bob | 74 | No | 0 | ||
| 4 | Cy | 58 | Yes | 3 | ||
| 5 | Dee | 81 | No | 1 | ||
| 6 | Eli | 66 | 2 |
Enter — commit · F2 — edit · F4 — $ in a reference · Ctrl+C/Ctrl+V — copy and paste · Ctrl+Z — undo
Esc or F6 — leave the sheet for the «Check» button · Shift+Tab in the first cell — back to the page