Select Case Statement with Multiple Expressions

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CEO123
    New Member
    • Jan 2010
    • 1

    Select Case Statement with Multiple Expressions

    Does anyone know if it is possible and the syntax to test mutlitple expressions in a select case statement? This is the best I could come up with but it doesn't appear to be working

    Example:

    Code:
    Select Case rng1.value And rng2.value
    
    Case rng1.value = 1 & rng2.value = 2
    
    'code here
    
    case rng1.value = 2 & rng.value = 2
    
    'code here
    
    End Select
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    You could try something like this
    Code:
    Sub TestSelect(ByVal Value1 As Integer, ByVal Value2 As Integer)
        
        Select Case True
            Case (Value1 = 1 And Value2 = 2)
                MsgBox "Value 1 = " & Value1 & " : Value 2 = " & Value2
            Case (Value1 = 2 And Value2 = 2)
                MsgBox "Value 1 = " & Value1 & " : Value 2 = " & Value2
        End Select
    
    End Sub
    
    Sub Test()
    
        TestSelect 1, 2
        
        TestSelect 2, 2
        
        TestSelect 2, 1
        
    End Sub
    ??


    MTB

    Comment

    • WannabePrgmr
      New Member
      • Jan 2010
      • 78

      #3
      I have a quick question for MTB.

      Do I need to use the Sub Test() with the TestSelect statements to make the above code work?

      I have a similar situation where I need to evaluate two different fields on a form where the outcome of a third combobox depends on it.

      I just don't understand the Sub Test part of your example.

      Thanks

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        that part just calls TestSelect to show you as an example.

        Comment

        Working...