VBA Function: Choose

The VBA function Choose returns a value from its list of arguments based on a number.

Usage:

Choose(number, value_1, value_2, value_3, etc)


Example of Usage

Displaying one of the 3 values based on the value of the choice variable:

Sub example()

    choice = 1

    course = Choose(choice, "Excel", "VBA", "Google Sheets")

    MsgBox "Chosen course: " & course 'Chosen course: Excel

End Sub

An alternative to the Choose function is to use an Array:

Sub example()

    choice = 1

    course = Array("Excel", "VBA", "Google Sheets")(choice)

    MsgBox "Chosen course: " & course 'Chosen course: VBA

End Sub
The first value in the Choose function is at position 1, unlike the array where the first value is at 0.