totn Excel Functions

MS Excel: How to use the SWITCH Function (WS)

This Excel tutorial explains how to use the Excel SWITCH function with syntax and examples.

Description

The Microsoft Excel SWITCH function compares an expression to a list of values and returns the corresponding result.

The SWITCH function is a built-in function in Excel that is categorized as a Logical Function. It can be used as a worksheet function (WS) in Excel. As a worksheet function, the SWITCH function can be entered as part of a formula in a cell of a worksheet.

Please read our SWITCH function (VBA) page if you are looking for the VBA version of the SWITCH function as it has a very different syntax.

subscribe button Subscribe


If you want to follow along with this tutorial, download the example spreadsheet.

Download Example

Syntax

The syntax for the SWITCH function in Microsoft Excel is:

SWITCH ( expression, value1, result1, value2, result2, ... value_n, result_n [, default] )

Parameters or Arguments

expression
The expression to compare to a list of values.
value1, value2, ... value_n
A list of values that are compared to expression. The SWITCH function is looking for the first value that matches the expression.
result1, result2, ... result_n
A list of results. The SWITCH function returns the corresponding result when a value matches expression.
default
Optional. It is the default to return if expression does not match any of the values (value1, value2, ... value_n).

Returns

The SWITCH function returns any datatype such as a string, numeric, date, etc.

Applies To

  • Excel for Office 365, Excel 2019

Type of Function

  • Worksheet function (WS)

Example (as Worksheet Function)

Let's look at some Excel SWITCH function examples and explore how to use the SWITCH function as a worksheet function in Microsoft Excel:

Microsoft Excel

Based on the Excel spreadsheet above, the following SWITCH examples would return:

=SWITCH(A2,"Excel","TechOnTheNet.com","Minecraft","DigMinecraft.com","Unknown")
Result: DigMinecraft.com

=SWITCH(A3,"Excel","TechOnTheNet.com","Minecraft","DigMinecraft.com","Unknown")
Result: TechOnTheNet.com

=SWITCH(A4,"Excel","TechOnTheNet.com","Minecraft","DigMinecraft.com","Unknown")
Result: Unknown  'The default is returned since there is no match

More Examples

Here are more examples that show how to use the SWITCH function in Excel: