Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 9999
  • Last Modified:

VBA "Select Case" multiple conditions

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
andy7789
Asked:
andy7789
  • 2
  • 2
2 Solutions
 
JPJ78Commented:
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
 
andy7789Author Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you mean:
Select Case true
     Case a OR c OR d
     'do something
     Case b 
     'do something
End select

Open in new window

0
 
andy7789Author Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I see. no, that is NOT possible with the CASE statement.
CASE will run and exit on the first match.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now