SWITCH function

This article describes the formula syntax and usage of SWITCH, one of the logical functions in Microsoft Excel.

Important: This function is available if you are an Office 365 subscriber and have the latest version of Office installed. It's also available with Excel Online, Excel Mobile and Excel for Android phones and tablets.

Description

The SWITCH function evaluates one value (called the expression) against a list of values, and returns the result corresponding to the first matching value. If there is no match, an optional default value may be returned.

Syntax

SWITCH(expression, value1, result1, [default or value2, result2],…[default or value3, result3])

Argument

Description

expression
(required)

Expression is the value (such as a number, date or some text) that will be compared against value1…value126.

value1…value126

ValueN is a value that will be compared against expression.

result1…result126

ResultN is the value to be returned when the corresponding valueN argument matches expression. ResultN and must be supplied for each corresponding valueN argument.

default
(optional)

Default is the value to return in case no matches are found in the valueN expressions. The Default argument is identified by having no corresponding resultN expression (see examples). Default must be the final argument in the function.

Because functions are limited to 254 arguments, you can use up to 126 pairs of value and result arguments.

Overview

In its simplest form, the SWITCH function says:

  • =SWITCH(Value to switch, Value to match1...[2-126], Value to return if there's a match1...[2-126], Value to return if there's no match)

Where you can evaluate up to 126 matching values and results.

See the following formula:

Breakdown of the SWITCH function's arguments
  1. Value to switch? In this case, WEEKDAY(A2) equals 2.

  2. What value do you want to match? In this case, it's 1, 2 and 3.

  3. If there's a match, what do you want to return as a result? In this case, it would be Sunday for 1, Monday for 2 and Tuesday for 3.

  4. Default value to return if there's no match found. In this case, it's the text "No match".

    Note: If there are no matching values, and no default argument is supplied, the SWITCH function returns the #N/A! error.

Examples

You can copy the example data in the following table and paste it in cell A1 of a new Excel worksheet to see the SWITCH function in action. If the formulas don't show results, you can select them, then press F2 > Enter. If you need to, you can adjust the column widths to see all the data.

Example

Value

Formula

Result

2

=SWITCH(WEEKDAY(A2),1,"Sunday",2,"Monday",3,"Tuesday","No match")

Because A2=2, and Monday is the result argument corresponding to the value 2, SWITCH returns Monday

99

=SWITCH(A3,1,"Sunday",2,"Monday",3,"Tuesday")

Because there's no match and no else argument, SWITCH returns #N/A!

99

=SWITCH(A4,1,"Sunday",2,"Monday",3,"Tuesday","No match")

No match

2

=SWITCH(A5,1,"Sunday",7,"Saturday","weekday")

weekday

3

=SWITCH(A6,1,"Sunday",2,"Monday",3,"Tuesday","No match")

Tuesday

Do you have a specific function question?

Post a question in the Excel community forum

Help us improve Excel

Do you have suggestions about how we can improve the next version of Excel? If so, please check out the topics at Excel User Voice

See Also

VLOOKUP function

CHOOSE function

IF function

IFS function

Overview of formulas in Excel

How to avoid broken formulas

Find and correct errors in formulas

Excel keyboard shortcuts and function keys

Logical functions (reference)

Excel functions (alphabetical)

Excel functions (by category)

Share Facebook Facebook Twitter Twitter Email Email

Was this information helpful?

Great! Any other feedback?

How can we improve it?

Thank you for your feedback!

×