ExcelReady
CourseFunction guidesBlog
Start freeStart learning for free
ExcelReady

Be Excel-ready before the interview. Hands-on practice in your browser, with instant feedback.

Learn

  • Course
  • Function guides
  • Blog

Product

  • Certificate

Company

  • Editorial policy
  • Contact
  • Terms
  • Privacy

© 2026 ExcelReady. All rights reserved.

  1. Blog
  2. Logic
  3. The SWITCH Function in Excel (Turn Codes Into Labels)

The SWITCH Function in Excel (Turn Codes Into Labels)

By ExcelReady Team·Updated October 30, 2026·7 min read

The short answer

The Excel SWITCH function compares one value with a list of options and returns the result paired with the first exact match: =SWITCH(D2,"P","Pending","S","Shipped","Other"). The last single value is the default, shown when nothing matches. Without a default, SWITCH returns #N/A. SWITCH needs Excel 2019 or later.

Key takeaways

  • SWITCH checks one value against exact options; each option is followed by its result.
  • An extra value at the very end is the default, shown when no option matches.
  • Without a default, a value with no match returns #N/A.
  • SWITCH only does exact matches; for ranges like >=90, use IFS or nested IF.
  • SWITCH needs Excel 2019, Excel 2021 or Microsoft 365; older versions show #NAME?.
On this page+
  1. How does the Excel SWITCH function work?
  2. How to turn codes into labels with SWITCH
  3. How to add a default value
  4. How does SWITCH compare with IF and IFS?
  5. How to use SWITCH with numbers and other functions
  6. When should you use a lookup table instead?
  7. What are the common SWITCH mistakes?
  8. Practise it

The Excel SWITCH function turns short codes into readable labels. You give it one value, such as a status code, and a list of possible matches with their results. It returns the result for the first exact match, or a default if nothing matches. This guide covers the syntax, the default value, and when IFS or a lookup table is the better tool.

How does the Excel SWITCH function work?#

SWITCH compares one value, the expression, with each option in turn. When an option matches exactly, it returns the result paired with it:

Excel formula
=SWITCH(expression, value1, result1, [value2, result2], ..., [default])
PartWhat it meansExample
expressionThe value to check, usually a cellD2
value1, result1An option and the result to show when it matches"P","Pending"
defaultOptional. One extra value at the end, shown when nothing matches"Check code"

You can list up to 126 pairs. SWITCH works in Excel 2019, Excel 2021, Excel 2024, Microsoft 365 and Excel for the web.

How to turn codes into labels with SWITCH#

An order export often stores status as one letter. SWITCH translates each code:

Excel formula
=SWITCH(D2,"P","Pending","S","Shipped","D","Delivered")
OrderCodeStatus
2041SShipped
2042PPending
2043DDelivered
2047R#N/A

Text codes and labels both need double quotes. Numbers don't: =SWITCH(B2,1,"High",2,"Medium",3,"Low") works on numeric codes.

Look at the last row. R isn't in the list, so SWITCH has nothing to return and shows #N/A.

To build the formula yourself:

  1. Click the first empty cell of the Status column and type =SWITCH(.
  2. Click the code cell, D2, and type a comma.
  3. Type each code and its label as a pair, with commas between them: "P","Pending","S","Shipped",.
  4. Finish the last pair, close the bracket and press Enter.
  5. Fill down with Ctrl+D (Windows) or ⌘D (Mac). D2 changes to D3, D4 and so on.

Check the pairs before you fill down. If a code and its label are the wrong way round, SWITCH won't warn you; it just never finds a match.

How to add a default value#

Add one extra value after the last pair, with no option in front of it. SWITCH shows it whenever nothing matches:

Excel formula
=SWITCH(D2,"P","Pending","S","Shipped","D","Delivered","Check code")

Now the R row shows "Check code" instead of #N/A. A default is good practice in almost every SWITCH formula, because new codes and typos turn up in real data. Make the default say something useful, so readers know the row needs a look.

Don't use IFERROR to hide the #N/A instead. A default handles the "no match" case on purpose, while IFERROR would also hide other problems. See IFERROR, used the right way for when wrapping makes sense.

How does SWITCH compare with IF and IFS?#

Use SWITCH when you check one cell against exact values. Use IFS or nested IF when the tests are ranges or different conditions. Here is the same code lookup written three ways:

Excel formula
=IF(D2="P","Pending",IF(D2="S","Shipped",IF(D2="D","Delivered","Check code")))
=IFS(D2="P","Pending",D2="S","Shipped",D2="D","Delivered",TRUE,"Check code")
=SWITCH(D2,"P","Pending","S","Shipped","D","Delivered","Check code")
Nested IFIFSSWITCH
Repeats the cellIn every testIn every testOnce
Handles ranges like >=90YesYesNot directly
"Otherwise" resultThe last FALSE resultA final TRUE, pairA single value at the end
Works in older ExcelYesExcel 2019 or laterExcel 2019 or later

SWITCH is the shortest because the cell appears once. For grades, price bands and other ranges, read the nested IF guide for grades and bands or the IFS function guide. If plain IF is still new, start with the Excel IF function explained simply.

Can SWITCH handle ranges?#

There is a well-known workaround: switch on TRUE, and use tests as the options.

Excel formula
=SWITCH(TRUE,B2>=90,"A",B2>=80,"B",B2>=70,"C","F")

SWITCH returns the result for the first test that equals TRUE. It works, but IFS says the same thing more plainly, so most people keep SWITCH for exact codes.

How to use SWITCH with numbers and other functions#

The expression can be a formula, not just a cell. A common example names days of the week from WEEKDAY, which returns 1 for Sunday through 7 for Saturday:

Excel formula
=SWITCH(WEEKDAY(B2),1,"Sunday",7,"Saturday","Weekday")

For a date that falls on a Saturday, this gives "Saturday". For Monday to Friday it gives "Weekday", thanks to the default. Excel works out WEEKDAY once, then compares the result with each option.

When should you use a lookup table instead?#

Use a lookup table when the list is long or changes often. Ten or more codes in one formula are hard to read, and every new code means editing every copy of the formula.

Put the codes in one column and the labels in the next, then look them up:

Excel formula
=XLOOKUP(D2,$K$2:$K$12,$L$2:$L$12,"Check code")

XLOOKUP needs Excel 2021 or Microsoft 365. The fourth argument does the same job as SWITCH's default. When a new code appears, you add a row to the table and every formula picks it up.

What are the common SWITCH mistakes?#

MistakeWhat you seeFix
No default#N/A for unknown codesAdd a final value, like "Check code"
Text codes without quotes: P#NAME?Write "P"
Options and results swappedThe wrong labelsOption first, then its result
Extra space in the data, like "P "The default or #N/AClean the data with TRIM
Number stored as text, like "1"No match for 1Convert the codes to real numbers
Older Excel version#NAME?Use nested IF or a lookup table

The last two data problems are easy to miss, because the cell looks right. Check suspicious cells with ISNUMBER, ISTEXT and ISBLANK, or use LEN to count the characters.

Practise it#

Try the priority exercise on this page, then practise SWITCH and the IS functions in a live spreadsheet. You'll check messy imported data with ISBLANK and ISNUMBER, then turn status codes into labels with SWITCH and add a default for a new code.

Try it yourself

This is a live spreadsheet. Type the formula in the green cell and press Enter.

Each ticket has a priority code: 1 = High, 2 = Medium, 3 = Low. In C2, use SWITCH on the code in B2 to show its label, and add Check as the default for any other code. Codes are numbers here, so they don't need quotes, but the labels do.

fx
ABCD
1
Ticket
Priority Code
Priority
2
T-1001
2
3
T-1002
1
4
T-1003
3
5
T-1004
4
6
T-1005
1
7
8
9

Tip: Start with =SWITCH(B2, then each code and its label: 1,"High", and so on. The default goes last, on its own.

Practise this in a lesson

LessonIS functions and SWITCHCheck what's really in a cell with ISBLANK, ISNUMBER and ISTEXT, and turn short codes into labels with SWITCH.Function guideIFSReplace messy nested IFs with Excel's IFS function. Examples for grades, tiers and SLAs, the catch-all trick, and a live exercise.

Frequently asked questions

What does the SWITCH function do in Excel?

+

SWITCH compares one value with a list of options and returns the result next to the first one that matches exactly. It replaces a chain of IF tests on the same cell.

How do I add a default value to SWITCH?

+

Add one extra value after the last pair, with no option in front of it: =SWITCH(D2,"P","Pending","S","Shipped","Check code"). It shows whenever nothing matches.

Why does SWITCH return #N/A?

+

The value didn't match any option, and the formula has no default. Add a default as the last argument, or check the data for typos and extra spaces.

Can SWITCH test ranges like greater than 90?

+

Not directly, because it only checks exact matches. A common workaround is =SWITCH(TRUE,B2>=90,"A",B2>=80,"B","C"), but IFS is clearer for ranges.

Which Excel versions have SWITCH?

+

SWITCH is in Excel 2019, Excel 2021, Excel 2024, Microsoft 365 and Excel for the web. Earlier versions show #NAME?, so use nested IF or a lookup table there.

Sources

  • SWITCH function - Microsoft Support
  • IFS function - Microsoft Support

Written and checked by the ExcelReady Team. First published October 30, 2026. The practice exercise runs in the same formula engine as our lessons. Found a mistake? Read our editorial policy or email hello@excelready.app.

On this page

  1. How does the Excel SWITCH function work?
  2. How to turn codes into labels with SWITCH
  3. How to add a default value
  4. How does SWITCH compare with IF and IFS?
  5. How to use SWITCH with numbers and other functions
  6. When should you use a lookup table instead?
  7. What are the common SWITCH mistakes?
  8. Practise it

Keep reading

Logic· 6 min read

ISBLANK, ISNUMBER and ISTEXT in Excel

ISBLANK returns TRUE when a cell is completely empty, ISNUMBER returns TRUE when it holds a real number, and ISTEXT returns TRUE when it holds text. Each takes one cell, like =ISBLANK(C2). They are most useful inside IF, for example =IF(ISNUMBER(C2),"OK","Check"), to catch bad data before you calculate with it.

Logic· 6 min read

The Excel IF Function Explained Simply

The Excel IF function checks a condition and returns one value when it's TRUE and another when it's FALSE. The syntax is =IF(logical_test, value_if_true, value_if_false). For example, =IF(B2>=70,"Pass","Fail") shows Pass for a score of 70 or more and Fail for anything lower. Text results go in double quotes.

Logic· 6 min read

Nested IF in Excel: Grades, Bands and Tiers

A nested IF puts a second IF in the value_if_false slot of the first, so one formula can return three or more results. For grades: =IF(B2>=90,"A",IF(B2>=80,"B",IF(B2>=70,"C","F"))). Excel checks the tests in order and stops at the first TRUE one, so test the highest band first.

Don't just read about Excel. Do it.

Practise real formulas in a live spreadsheet with instant feedback. The first lessons are free, with no download.

Start learning for free