Ad space (banner)
Lesson 16 / 20

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.

๐Ÿ“– Reference code
โœ๏ธ Your code
Type your code, then press "Run"

๐Ÿงช 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).

Ad space (banner)
Ad space (in-article)