CHOOSE(index, choice1 [,choice2] [,])

Returns the value from a list of values based on an index number (Variant).

indexThe index number (Integer).
choice1The expression containing the first possible choice (Variant).
choice2(Optional) The expression containing the second possible choice (Variant).

* The "index" can be any numeric expression.
* If "index" = 1 then "choice1" is returned.
* If "index" = 2 then "choice2" is returned.
* If "index" < 1, then Null is returned.
* If "index" > the number of choices, then Null is returned.
* If "index" is not a whole number, then it is rounded to the nearest whole number.
* All the choices have to be submitted as individual items, you cannot pass in an array.
* Every choice is evaluated in the list, even though only one is returned.
* This can be quickly used to return a selection without having to create an array.
* The equivalent Excel function is Application.WorksheetFunction.Choose
* The equivalent .NET function is Microsoft.VisualBasic.Interaction.Choose
* For the Microsoft documentation refer to

Dim sReturn As String 
sReturn = Choose(1, "one", "two", "three")
Debug.Print sReturn '= "one"

sReturn = Choose(2, "one", "two", "three")
Debug.Print sReturn '= "two"

sReturn = Choose(3, "one", "two", "three")
Debug.Print sReturn '= "three"

© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited Top