PDA

View Full Version : Excel/VBA date compare not working



austenr
09-03-2010, 08:01 AM
I am having an issue where a certain date field in Excel sheet will not compare properly when checked in VBA.
I am only using a simple IF statement i.e.


If Sheets("Input + Wksheet").Range("D9").Value < "07/01/1996" Then


and the date keeps dropping in even when it IS greater than the criteria.
Can someone help me with the formatting mismatch from the Excel Sheet to the VBA code? Sample WB attached

GTO
09-03-2010, 08:15 AM
Hi Austen,

I did not look at the file, but I think you want:

If Range("A1").Value < DateValue("07/01/1996") Then

Have a great day,

Mark

austenr
09-03-2010, 08:42 AM
thanks Mark. That got it. Sometimes you stare at it too long you need a fresh set of eyes.

GTO
09-03-2010, 08:59 AM
...Sometimes you stare at it too long you need a fresh set of eyes.

Trust me, I am all too painfully aware of my own tired eyes :bug: (what a week!)