Solved

VBA "Select Case" multiple conditions

Posted on 2009-06-30
5
9,297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month10 days, 9 hours left to enroll

628 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