Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fall through a Select Case in Excel VBA?

Given

Select Case cmd

    case "ONE":   MsgBox "one"

    case "TWO":   MsgBox "two"

    case "THREE": MsgBox "three"

End select

My requirement is if cmd = "ONE" I need "one" and then "two" displayed however currently I am getting "one" displayed and then the program is breaking out of the select case...

like image 742
Kevin Boyd Avatar asked Oct 12 '09 21:10

Kevin Boyd


People also ask

How do you switch cases in VBA?

VBA Switch Case – Example #1Step 1: Insert a new module inside Visual Basic Editor (VBE). Click on Insert tab > select Module. Step 2: Define a new subprocedure within the inserted module that can hold your macro. Step 3: Define a new variable named usrInpt which can hold the user value.

Which clause is used to end a case statement VBA?

If testexpression matches any Case expressionlist expression, the statements following that Case clause are executed up to the next Case clause, or, for the last clause, up to End Select.

In what situation you will use Select Case statement?

Select Case is useful when you have three or more conditions that you want to check. You can also use this with two conditions (but I feel If Then Else is easier to use in those cases).


1 Answers

Select Case cmd
    case "ONE", "TWO":   
                  if cmd = "ONE" THEN
                      MsgBox "one"
                  end if
                  MsgBox "two"

    case "THREE": MsgBox "three"

End select
like image 106
manji Avatar answered Sep 23 '22 11:09

manji