fxExcelReps
← All functions ? Logical · Intermediate

SWITCH Map codes to results.

How to use SWITCH in Excel

SWITCH compares one value against a list and returns the matching result — a tidy replacement for nested IFs when you're mapping codes to names.

Syntax

=SWITCH(expression, value1, result1, [...], [default])

expressionThe value to check, e.g. a cell.
value1, result1, …Pairs of a possible value and what to return for it.
[default]Optional last argument returned when nothing matches.

Examples

=SWITCH(A2, "S","Small", "M","Medium", "L","Large", "Unknown")Size codes to names.
=SWITCH(WEEKDAY(B2), 1,"Sun", 7,"Sat", "Weekday")Weekend label from a date.

Common mistakes

#N/A error
No match and no default. Always add a default as the last argument.
Ranges like >100
SWITCH only checks exact matches. For ranges use IFS.
#NAME? in older Excel
Needs Excel 2019 or Microsoft 365.

Available in: Excel 2019, 2021, Microsoft 365, Excel for the web

Related functions

IFSIFXLOOKUP

↑ Practise SWITCH in the sheet above