我有一个执行一些验证的宏。我简化了下面的代码以进行说明。
我如何调整代码以使之成为可能?谢谢您的帮助!
Sub blank()
'Validations
If Cells(10, 4).Value = "" Then
MsgBox "Please fill in Invoice Date"
End If
If Cells(11, 4).Value = "" Then
MsgBox "Please fill in Invoice Number"
End If
'Save As
ActiveWorkbook.SaveAs filename:="Lease Admin Processing Input Form"
End Sub
您可以这样做:
Sub blank()
If Cells(10, 4).Value = "" Or Cells(11, 4).Value = "" Then
MsgBox "Please fill in both Invoice Number and Invoice Date"
Else
ActiveWorkbook.SaveAs filename:="Lease Admin Processing Input Form"
End If
End Sub
只需检查两个验证是否都正确。如果它们都成立,则运行“另存为”部分,否则将跳过另存为:)
Sub blank()
'Validations
If Cells(10, 4).Value = "" Then
MsgBox "Please fill in Invoice Date"
End If
If Cells(11, 4).Value = "" Then
MsgBox "Please fill in Invoice Number"
End If
If Cells(10, 4).Value = "" And Cells(11, 4).Value = "" Then
'Save As
ActiveWorkbook.SaveAs filename:="Lease Admin Processing Input Form"
End If
End Sub
也许像这样
Sub blank()
Dim bolChecker as boolean
bolChecker = false
'Validations
If Cells(10, 4).Value = "" Then
MsgBox "Please fill in Invoice Date"
bolChecker = true
End If
If Cells(11, 4).Value = "" Then
MsgBox "Please fill in Invoice Number"
bolChecker = true
End If
'Save As
if bolChecker = false then ActiveWorkbook.SaveAs filename:="Lease Admin Processing Input Form"
End Sub