- 01Setting up (what you'll need)
- 02Your first output (MsgBox)
- 03Variables (Dim)
- 04Branching (the If statement)
- 05Repeating (the For statement)
- 06Repeating (the Do While statement)
- 07Writing a Sub procedure
- 08Function procedures (work that returns a value)
- 09Reading and writing cells (Range and Cells)
- 10Working with arrays
- 11Working with strings
- 12The With statement
- 13Object variables and working with worksheets
- 14Looping over cells (For Each)
- 15Error handling (On Error)
- 16The Select Case statement
- 17Arguments (ByVal and ByRef)
- 18Working with collections (Collection)
- 19Recording macros and event procedures
- 20[Project] Build a small inventory sheet
The Select Case statement
This lesson covers the Select Case statement, which branches on several possible values.
Writing Select Case variable Case value1 ... Case value2 ... Case Else ... End Select lets you write several branches for one value. It corresponds to the switch statement of other languages.
The sample code shows a different message depending on a number representing the day of the week. Case Else is the default branch meaning "everything else".
A common early stumble is stacking up so many If/ElseIf branches that the code becomes hard to read. When one variable drives many branches, Select Case keeps it tidy.
In professional work, Select Case is used when work is split by a fixed set of values — a department code, a status code.
๐งช This site can't compile or run VBA directly, so it checks on the spot whether what you typed matches the reference code (scoring happens entirely in your browser โ nothing is sent anywhere).
