View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Brandt Brandt is offline
external usenet poster
 
Posts: 33
Default Select Case syntax for multiple conditions ("and")?

ker_01,

Per the vba help file: "If testexpression matches an expressionlist
expression in more than one Case clause, only the statements following the
first match are executed." Therfore, you dont need to worry about the "and"
statement because the second half of it (upperbound in your case) has
already been checked by the previous statement.

For example (not tested):

Select Case MyVar
Case MyVar 0.2
'do stuff
Case MyVar 0.02 ' if we got this far we already know MyVar <= 0.2
'do stuff
Case MyVar -0.02 'Only get to this point if MyVar <= 0.02
'do stuff
Case Else
'do default stuff
End Select

Hope this helps
Brandt

"ker_01" wrote:


I have a series of values (percentages) to process through a select case
statement. Cases include:
.2 ' more than 20%
.02 AND <=.2 ' between 2% and 20%
-.0199 AND <.0199 ' between +/-2%
-.0499 AND <-.0199 ' between -5% and -2%

etc.

I'm having trouble figuring out the syntax for a case range statement. I
thought I had it with
Select Case MyVar
Case (MyVar .2)
'do stuff
Case (MyVar .02) AND (MyVar <=.2)
'do stuff
Case (MyVar -.02) AND (MyVar<=.02)

but that isn't working.

What is the proper way to use a range of values that includes [greater than]
and [less than or equal to] as an AND criteria?

Thank you!
Keith