我正在尝试使用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
您将引用这样的范围:
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