VBA Select 案例是多个条件

VBA Select Case is multiple criteria

我有下面的一段代码,想稍微修改一下。基本上每个 case is 我都想检查次要标准。例如 Case is = "Lottery" 我想添加 AND range("SalesChannel").value = "SMB"。然后我想复制每个案例都使用不同的值(不是 SMB)。这可以做到吗?

Private Sub CommandButton1_Click()

With LoginPassword.TextBox1.Value
Select Case Me.TextBox1.Value
    Case Is = "Lottery"
        LoginPassword.Hide
        SMB_Login
        CalculateFinancials
    Case Is = "Charity"
        LoginPassword.Hide
        DCS_Login
        CalculateFinancials
    Case Is = "Curfew"
        LoginPassword.Hide
        Campaign_Login
        CalculateFinancials
    Case Is = "Europe"
        LoginPassword.Hide
        Eureka_Login
        CalculateFinancials
    Case Is = "Promo"
        LoginPassword.Hide
        Promo_Login
        CalculateFinancials
    Case Is = "Sundew"
        LoginPassword.Hide
        Loyalty_Login
        CalculateFinancials
    Case Is = "Casino"
        LoginPassword.Hide
        MobilePricing.Hide
        Range("Network").ClearContents
    Case Is = "RedDevil"
        HardwareUpdateYesNo
    Case Is = "Provision"
        LoginPassword.Hide
        MobilePricing.Hide
        ProvisioningView
    Case Else
        MsgBox "Password Incorrect!", vbCritical + vbOKOnly, "Login Failed!"
        TextBox1.Text = ""
        TextBox1.SetFocus
End Select
End With

End Sub

这是一个示例 Select 具有多个条件的案例:

Option Explicit

Public Sub TestMe()

    Select Case True        
        Case 1 = 1 And True 
            Debug.Print 1
        Case True And 2 = 5
            Debug.Print 2
        Case True And 5 = 5 And 6 = 7
            Debug.Print 3
    End Select

End Sub

在你的情况下,你应该简单地写下你的条件,而不是 1=1True。像这样: Case Me.TextBox1.Value = "Lottery" and range("SalesChannel").value = "SMB" 但是把 Select Case True 留在上面。