willow1985
Well-known Member
- Joined
- Jul 24, 2019
- Messages
- 929
- Office Version
- 365
- Platform
- Windows
Hello,
I am trying to have a certain cell locked (B2) that only a certain date format can be entered but I keep getting an error with the code. Perhaps you can shed some light on what I am doing wrong? Still very new to this.
Thank you
I am trying to have a certain cell locked (B2) that only a certain date format can be entered but I keep getting an error with the code. Perhaps you can shed some light on what I am doing wrong? Still very new to this.
Thank you
Code:
Private Sub Worksheet_Change()
Call ValidateDate(2) 'For Column B2:B2
End Sub
Private Sub ValidateDate()
Set r = ActiveSheet.Range(Cells(2, Col), Cells(2, Col))
For Each c In r
If c.Value <> "" And Not IsDate(c) Then
c.ClearContents
MsgBox "Please enter Date Returned in the following format: MM/DD/YYYY"
End If
Next c
ActiveSheet.Range("B2:B2").NumberFormat = "[$-409]d-mmm-yy;@"
End Sub