Using the Select Case structure
This recipe covers yet another control structure, the Select Case structure. There are similarities between this and the If-Then-Else structure, which will make it easier to understand the working process. This structure works well enough when you have only two options to choose between, but excels when you have to make decisions between three or more options.
Getting ready
Make sure that ProgramFlow.xlsm
is still active. Clear Sheet1 of any data and enter the following numbers in column A:
Press Alt + F11 to switch to the VBA Editor. With that open, insert a new module.
How to do it…
- Create a new Sub procedure. Call it
SelectCaseSample
, and then copy the following code:Sub SelectCaseSample()     Dim Mark As Integer     Range("A1").Select     Mark = ActiveCell.Value     Select...