带有多个“And”的“If”条件没有得到预期的结果

问题描述

使用条件允许一个按钮,我还是没有得到预期的结果。该按钮未考虑提到的条件。怎么来的

Private Sub CONFIRM2_Click()
    
    If NAMEC.Value = "" And DATEC.Value = "" And CREF.Value = "" And SPN.Value = "" And AMENDT.Value = "" And LINKA.Value = "" And BUDGETI.Value = "" And TOR.Value = "" And LINKA.Value = "" And DETAIL.Value = "" Then
        MsgBox "Thanks to fill all requested informations"
        Exit Sub
    ElseIf NAMEC.Value <> "" And DATEC.Value <> "" And CREF.Value <> "" And SPN.Value <> "" And AMENDT.Value <> "" And LINKA.Value <> "" And BUDGETI.Value <> "" And TOR.Value <> "" And LINKA.Value 

一些附加信息:我在条件中添加了一个字段 (TOR),但下面的 MsgBox(MsgBox“感谢填写所有请求的信息”)并未考虑该附加字段。怎么了?

解决方法

Select Case 而不是 If

Private Sub CONFIRM2_Click()
    
    Select Case ""
    Case NAMEC.Value,DATEC.Value,CREF.Value,SPN.Value,AMENDT.Value,_
            LINKA.Value,BUDGETI.Value,TOR.Value,DETAIL.Value
        MsgBox "Please fill in all of the requested information."
        ' Do whatever.
    Case Else
        MsgBox "Thanks for supplying the requested information"
        Exit Sub
    End Select
    
End Sub

简化版

Sub SelectCase()
    Select Case ""
    Case Range("A1").Value,Range("A2").Value
        MsgBox "Nope" ' Either A1,A2 or both are equal to ""
    Case Else
        MsgBox "Yupee" ' Both are not equal to "".
    End Select
End Sub

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...