I have a workbook with a field for a user to enter a date. In testing, I entered 11/31/21 which is not a valid date. I thought I would test for valid date entry and can't seem to make it work. I am trying to use IsDate to check and must being doing something wrong. I tried setting my cell value as both date and string with no luck.
Public Sub Worksheet_Change(ByVal Target As Range)
Dim PCell As Range
Dim Edate As Date
Set PCell = Range("S2")
Edate = Range("S2")
If Not Application.Intersect(PCell, Range(Target.Address)) _
Is Nothing Then
If IsDate(Edate) = 1 Then
ActiveWorkbook.Connections("Query - SelectedDataByDate").Refresh
Else
MsgBox ("You have entered an invalide date.")
End If
End If
End Sub