VBA If调用Msgbox的语句始终调用msgbox

问题描述 投票:0回答:1

我正在尝试使用if语句检查空格,如果有空白字段,则返回msgbox。如果没有空白字段,它将运行另一个代码块。但是,即使您填写了所有字段,也总是返回msgbox,并且下一个代码块不会运行。我是VBA的新手,并且用gneneral编写代码,因此任何建议都将有所帮助。

相关代码:

'Check required fields
    If IsEmpty(C3) Then
        MsgBox ("Fill out all required fields")
    ElseIf IsEmpty(C7) = True Then
        MsgBox ("Fill out all required fields")
    ElseIf IsEmpty(C9) = True Then
        MsgBox ("Fill out all required fields")
    ElseIf IsEmpty(C11) = True Then
        MsgBox ("Fill out all required fields")
    ElseIf IsEmpty(C13) = True Then
        MsgBox ("Fill out all required fields")
    ElseIf IsEmpty(C17) = True Then
        MsgBox ("Fill out all required fields")
    Else
vba if-statement msgbox
1个回答
0
投票

您将引用这样的范围:

If Len(Range("C3").Value) = 0 Then
    MsgBox "Fill out all required fields"

但是做这件事的时间要短一些:

If Application.CountA(Range("C3,C7,C11,C13,C17")) < 5 Then
    MsgBox "Fill out all required fields"
End if 
© www.soinside.com 2019 - 2024. All rights reserved.