-
Aug 22nd, 2012, 09:02 AM
#1
Thread Starter
New Member
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
-
Aug 22nd, 2012, 08:20 PM
#2
Fanatic Member
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.
-
Aug 23rd, 2012, 04:51 AM
#3
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|