Switch

Evaluate a list of expressions and return a value corresponding to the first expression that is TRUE.

Syntax
      Switch ( expr1, value1, expr2, value2, … expr_n, value_n )
Key
   expr1,expr2…    The expressions to evaluate.

   value1,value2 … A list of values

The switch() function can be used in VBA or in an SQL query.

Examples

Dim strDemo as String

strDemo = Switch (CountryID = 1, "USA", CountryID = 2, "Canada", CountryID > 2, "other" )

MsgBox strDemo

“The test of a good teacher is not how many questions he can ask his pupils that they will answer readily, but how many questions he inspires them to ask him which he finds it hard to answer” ~ Alice Wellington Rollins

Related:

If Then Else - If-Then-Else
Case - If Then Else
Nz - Detect a NULL value


 
Copyright © SS64.com 1999-2019
Some rights reserved