Excel单元格在两个日期之间进行多次验证,如果单元格不为空白

时间:2017-07-05 22:11:28

标签: excel

我需要对单元格进行两次验证。首先,如果用户输入了时间(B5)而不是日期(A5),则应该出现要求A5中的日期的弹出窗口。输入日期时,它必须在开始日期(B1)和结束日期(B2)之间。

1 个答案:

答案 0 :(得分:0)

这是一个简单的事情,因为你的细胞都是硬编码的。您可以根据需要编辑宏以获得更多功能并更加强大。

Sub doubleValidate()
    If ActiveSheet.Cells("B5") <> "" And ActiveSheet.Cells("A5") = "" Then
        MsgBox ("Please Enter Date!")
        End
    End If

    If ActiveSheet.Cells("A5") <= ActiveSheet.Cells("B2") And ActiveSheet.Cells("A5") >= ActiveSheet.Cells("B1") Then
        MsgBox ("All good.")
    End If

    If ActiveSheet.Cells("A5") > ActiveSheet.Cells("B2") Or ActiveSheet.Cells("A5") < ActiveSheet.Cells("B1") Then
        MsgBox ("Date not in range.")
    End If

End Sub

下次请展示一些自己的作品,以获得可靠的答案。