I have a column of dates. These will be incorporated into objects, one per row, along with other data in the row.
However, some of the cells in the date column are empty. As I test I create a date variable and set its value as the value of an empty cell. I msgbox'd the new value of the date and found it was "12:00 AM". Is there a constant built into VBA to represent this value, so I can do tests similar to:
If myDate = vbNullDate Then
I run into this problem from time to time. I usually do the below:
dim d as date
if d = cdate(0) then msgbox "Default value"
The default value for a local Date variable seems to be:
Saturday, December 30, 1899 12:00:00 AM
based on this procedure:
Sub testdate()
Dim d As Date
Debug.Print Format$(d, "Long Date") & " " & Format$(d, "Long Time")
End Sub
To check the default value for any variable type, simply declare a variable of that type, then print it's value.
Sub testint()
Dim d As Integer
Debug.Print d
End Sub
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With