Switch function

Category: Color / Misc

Summary

Returns first True expression's value.

Syntax

Switch(expr-1, value-1, [ expr-2, value-2…, [ expr-n, value-n ]]) The Switch function syntax has these parts:
Part
Description
exprRequired. Variant expression that you want to evaluate.
valueRequired. Value or expression to be returned if the corresponding expression is True.

Example

Example
This example uses the Switch function to return the name of a language that matches the name of a city.
Function MatchUp(CityName As String)
Matchup = Switch(CityName = "London", "English", CityName _
= "Rome", "Italian", CityName = "Paris", "French")
End Function

Microsoft Support Page

https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/switch-function

Back to Functions