Select CASE statement in Excel VBA

SELECT CASE instruction – introduction

Another instruction next to IF THEN ELSE used in the decision making process by our program is the SELECT CASE VBA statement . The instruction checks whether the instruction entered in the instructions is in accordance with the conditions stated in the instructions. On this basis, one scenario is chosen in our decision-making process. After selecting the scenario, the action stored in the block is executedCase scenario and the statement ends its operation. The Model CASE VBA statement model looks like this:

An example of the use of the Select CASE VBA instruction

For starters, let’s take a simple example. We want the word number to display its verbal description after entering the month number in the InputBox window . So for January it will be the number 1, for February 2, etc. In case when the value entered will go beyond the range 1-12, or the entered value will not be an integer, we will receive a message asking for the correct value.


Tasks (You can enter the solution in a comment)

  1. Based on the course section regarding the IF THEN ELSE instructions,  item 3. build an analogous example using the Select CASE statement.
  2. Based on the example in this chapter, write a program which after entering the number representing the day of the week will return its verbal version.

Leave a comment

Your email address will not be published. Required fields are marked *

One thought on “Select CASE statement in Excel VBA”

%d bloggers like this: