Consulting

Results 1 to 4 of 4

Thread: Excel/VBA date compare not working

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Excel/VBA date compare not working

    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.


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


    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
    Peace of mind is found in some of the strangest places.

  2. #2
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    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

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    thanks Mark. That got it. Sometimes you stare at it too long you need a fresh set of eyes.
    Peace of mind is found in some of the strangest places.

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    Quote Originally Posted by austenr
    ...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 (what a week!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •