help with case

  • Thread starter Thread starter Matthew Dyer
  • Start date Start date
M

Matthew Dyer

Here's what I've got:

Select Case Maxdpd
Case Is <= 39
dpdval = R15
Case Is <= 59 > 39
dpdval = R2
Case Is <= 89 > 59
dpdval = R3
Case Is > 89
dpdval = R4
End Select

As you can probably guess, this is not working. dpdval is returning 0
for every case except the <= 39. How do i fix this?
 
Matthew,

Case does not calculate OR type statements nor does it process multiple
cases as it falls through. Therefore, just remove the trailing ' > XX ' out
of each statement and you should find that it works.

DB
 
It will only execute the first case that meets the criteria.
Each case is effectively an Or statement in this particular code.

Select Case Maxdpd
Case Is <= 39 'If it is > 39 next case
dpdval = R15
Case Is <= 59 'If it is > 59 next case
dpdval = R2
Case Is <= 89 'If it is > 89 next case
dpdval = R3
Case Is > 89
dpdval = R4
End Select
 
Sub selecttry()
Dim x As Integer
Select Case Val(InputBox("num"))
Case 1 To 5: x = 1
Case 6 To 10: x = 2
Case Else
End Select
MsgBox x
End Sub
 
Matthew,
Don G's answer is the most correct. I totally forgot that you can test for
ranges.

DB
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top