WildBurrow
New Member
- Joined
- Apr 5, 2021
- Messages
- 41
- Office Version
- 365
- Platform
- Windows
I have the following code to ensure valid date;
The cell has a custom format for date as mm/dd/yy hh:mm
I've just discovered that is someone adds a zero to the beginning of the month, it isn't triggering the message. For example:
Actual date/time: 04/02/24 17:49
Entered date/time 004/02/24 17:49
Any idea why the IsDate function isn't recognizing this as an error?
VBA Code:
'Discovery date not valid
If Not Application.Intersect(target, range("I3")) Is Nothing Then
If (Not IsDate(target.Value)) Then
Application.EnableEvents = False
target.Value = Empty
target.Activate
Application.EnableEvents = True
MsgBox "Please enter valid date and time.", vbOKOnly + vbExclamation, "Discovery Date and Time Format: mm/dd/yy hh:mm"
End If
End If
The cell has a custom format for date as mm/dd/yy hh:mm
I've just discovered that is someone adds a zero to the beginning of the month, it isn't triggering the message. For example:
Actual date/time: 04/02/24 17:49
Entered date/time 004/02/24 17:49
Any idea why the IsDate function isn't recognizing this as an error?