Click here to Skip to main content
15,887,267 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using MS Office 2003 {VBA Excel}

I was wondering if there is a way to use the AND operator in SELECT CASE? I've tried it as is {below} but it's not working like that. If there isn't a way to do this I can use the IF...ELSEIF...ELSE, but I'd rather use SELECT CASE.

Select Case bMain
   Case Is = "Cat" And optLect.Value = True
      chkWkTemp.Value = True
   Case Is = "Lec" And optCat.Value = True
      chkWkTemp.Value = True
   Case Else
      chkWkTemp.Value = False
End Select

It just doesn't work like that and I haven't found any way of making sure BOTH statements in the first 2 CASEs are true, which is what I need for this.

Thanks in advance!

Peace to you and yours,
Matthew DraGon Stohler
Posted

1 solution

You can't use something like this: "Lec" And False in the Select ... Case ... End Select statement.

The correct statement is:
VB
Select Case optLect.Value
    Case True
        Select Case bMain
           Case Is = "Cat", "Lec" 
              chkWkTemp.Value = True
           Case Else
              chkWkTemp.Value = False
        End Select
    Case False
       '?
End Select


or
VB
Dim myVal as String

myVal = bMain & Cstr(optLect.Value)

Select Case myVal
    Case "LecTrue", "CatTrue"
        chkWkTemp.Value = True
    Case "LecFalse", "CatFalse"
        chkWkTemp.Value = False
End Select
 
Share this answer
 
Comments
Amir Mahfoozi 3-Dec-11 23:54pm    
My 5 ;)
Maciej Los 4-Dec-11 14:34pm    
Thank you!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900