Solved

VBA "Select Case" multiple conditions

Posted on 2009-06-30
5
8,868 Views
Last Modified: 2013-11-26
Hi x-perts,

Is there a way to write a Select Case statement with a FEW executable Case options, i.e. when a=true and b = true?

of course, I can write all IF statements, but it would be much easier with Select Case

Thanks
Select Case true
     Case a
     'do something
     Case b 
     'do something
End select

Open in new window

0
Comment
Question by:andy7789
  • 2
  • 2
5 Comments
 
LVL 10

Assisted Solution

by:JPJ78
JPJ78 earned 200 total points
ID: 24751809
I'm sorry, but I don't think you can.
You can write OR statements, but not AND.
OR statements are coma sepparated.


Select Case true
     Case a,c,d
     'do something
     Case b 
     'do something
End select

Open in new window

0
 

Author Comment

by:andy7789
ID: 24751825
I mean not INSIDE of a Case, but execute a few Case statements in a row, if conditions are satisfied, i.e. perform Case a AND Case b

is it possible somehow?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 24752038
you mean:
Select Case true
     Case a OR c OR d
     'do something
     Case b 
     'do something
End select

Open in new window

0
 

Author Comment

by:andy7789
ID: 24752355
Yes, if both the conditions are true, ex a = true and b = true, it will only execute the first, i.e. a=true condition and exit. Case b will not be checked and executed

what I need is to execute ALL individual Case statement, if the conditions are satisfied.
0
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 300 total points
ID: 24752387
I see. no, that is NOT possible with the CASE statement.
CASE will run and exit on the first match.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question