How to check if a date cell in Excel is empty?

前端 未结 3 1550
走了就别回头了
走了就别回头了 2020-12-20 16:32

If feels like this should be really easy but I dont get it to work without retrieving the value of the cell again.

To start with, I have 2 date cells:



        
3条回答
  •  庸人自扰
    2020-12-20 17:22

    As Excel Hero pointed out, a date variable cannot be empty. In fact, a date variable is a number, so you should be able to do something like this. Also, notice that the code below uses "Value2".

    Sub test()
        Dim d As Date
        d = Range("A1").Value2
        If d = 0 Then
          MsgBox "ok"
        Else
          MsgBox "not ok"
        End If
    End Sub
    

提交回复
热议问题