D
Dave
I have two cells in a workbook that are dates. The cell Start_Date has a
valid date in it. The second cell Test_Date is either blank or has a valid
date in it. The IsDate test on both cells works fine, however, on a blank
cell the Month function extracts "12". Anyone know why? I had to put the
month function within a test for IsDate to make it work. Seems like Month
function on a blank cell should return something other than a 12.
Dave
Test code:
If IsDate(Range("Start_Date")) Then 'Cell has 11/01/09 in it.
MsgBox ("start date a date") 'Displays
Else
MsgBox ("start date not a date")
End If
If IsDate(Range("Test_Date")) Then 'Cell is blank
MsgBox ("test date a date")
Else
MsgBox ("test date not a date") 'Displays
End If
MsgBox (Month(Range("Start_Date"))) 'Displays 11
MsgBox (Month(Range("Test_Date"))) ' Displays 12
If Month(Range("Start_Date")) = Month(Range("Test_Date")) Then
MsgBox ("Months equal")
Else
MsgBox ("months not equal") 'Displays
End If
valid date in it. The second cell Test_Date is either blank or has a valid
date in it. The IsDate test on both cells works fine, however, on a blank
cell the Month function extracts "12". Anyone know why? I had to put the
month function within a test for IsDate to make it work. Seems like Month
function on a blank cell should return something other than a 12.
Dave
Test code:
If IsDate(Range("Start_Date")) Then 'Cell has 11/01/09 in it.
MsgBox ("start date a date") 'Displays
Else
MsgBox ("start date not a date")
End If
If IsDate(Range("Test_Date")) Then 'Cell is blank
MsgBox ("test date a date")
Else
MsgBox ("test date not a date") 'Displays
End If
MsgBox (Month(Range("Start_Date"))) 'Displays 11
MsgBox (Month(Range("Test_Date"))) ' Displays 12
If Month(Range("Start_Date")) = Month(Range("Test_Date")) Then
MsgBox ("Months equal")
Else
MsgBox ("months not equal") 'Displays
End If