Results 1 to 3 of 3

Thread: Excel - Code to determine if date in a cell is a real date

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2012
    Posts
    12

    Question Excel - Code to determine if date in a cell is a real date

    Good morning!

    Here's my latest predicament. On rare occasions I've found non-existant dates (ie., 31-Feb-12) entered into the date column ("O") of one of our spreadsheets. That data feeds other formulas, macros, etc. and is easily overlooked during manual review as it's one of nearly 200 dates.

    I'd like to add a few lines of code that would check the dates as entered to see if they are "real" dates, and if not then set the fill color to red, text to white, and add 1 to an error counter which eventually feeds a msg box that tells the user that x amount of errors were found.

    Any help would be greatly appreciated.


    Thanks,
    Frank.M

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Excel - Code to determine if date in a cell is a real date

    You might be able to use the Day() worksheet function. It returns #Value! for an invalid date.

  3. #3
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Excel - Code to determine if date in a cell is a real date

    even the date posted above would to vba be a real date, by implicit conversion

    ?day("31-Feb-12")
    12
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

Tags for this Thread

Posting Permissions

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



Click Here to Expand Forum to Full Width