Lil Stinker
Board Regular
- Joined
- Feb 16, 2022
- Messages
- 151
- Office Version
- 2019
- Platform
- Windows
Hey guys,
I'm looking for a way to highlight a date error when a user enters an end date that is earlier than the start date.
My end date is located in C23. My start date range is in F16:F26.
I currently use the following to highlight the incorrect date if the date entered in any of the cells in the start date range is incorrect:
This seems to work as long as the incorrect date is entered anywhere in the start date range but not if the incorrect date is entered in the end date cell. How can I change the end date font color and throw in a msgbox if the incorrect date is entered in the end date cell based on any one of the dates in the start date range?
I'm looking for a way to highlight a date error when a user enters an end date that is earlier than the start date.
My end date is located in C23. My start date range is in F16:F26.
I currently use the following to highlight the incorrect date if the date entered in any of the cells in the start date range is incorrect:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Range("F16:F26")) Is Nothing And IsDate(Target) = True Then
If Target.Value > Range("C23").Value Then
Target.Font.Color = RGB(255, 0, 0) 'no good, red font
Range("C23").Font.Color = RGB(255, 0, 0)
MsgBox "Billing End Date cannot occur before Billing Start Date.", vbExclamation, "Check ya dates!"
Else
Target.Font.Color = RGB(0, 0, 0) 'all good, black font
Range("C23").Font.Color = RGB(0, 0, 0)
End If
End If
This seems to work as long as the incorrect date is entered anywhere in the start date range but not if the incorrect date is entered in the end date cell. How can I change the end date font color and throw in a msgbox if the incorrect date is entered in the end date cell based on any one of the dates in the start date range?