VBA Select Case是多个标准

时间:2017-07-12 09:20:24

标签: excel vba excel-vba with-statement select-case

我有以下代码,想稍微修改一下。基本上每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

1 个答案:

答案 0 :(得分:1)

这是一个包含多个条件的示例选择案例:

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留在顶部。