tiredofit
Well-known Member
- Joined
- Apr 11, 2013
- Messages
- 1,834
- Office Version
- 365
- 2019
- Platform
- Windows
The max date in Excel is 31 Dec 9999, which corresponds to the value 2958465.
How can I restrict users from entering a date after this value, using just VBA (as opposed to the Data Validation found under Data in the ribbon)?
The code below shows an Overflow error (when the cell I am inputting the date is formatted to Date).
This is the best I can do:
Thanks
How can I restrict users from entering a date after this value, using just VBA (as opposed to the Data Validation found under Data in the ribbon)?
The code below shows an Overflow error (when the cell I am inputting the date is formatted to Date).
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Value > 2958465 Then
End If
End Sub
This is the best I can do:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Target.NumberFormat = "General"
If Target.Value > 2958465 Then
Target.Value = vbNullString
MsgBox "too large"
Else
Target.NumberFormat = "dd/mm/yyyy;@"
End If
End Sub
Thanks
Last edited: