PDA

View Full Version : Date validation in VBA



wrightyrx7
03-28-2012, 11:57 AM
Hi All,

Desperate to get a data validation on columns E and F in VBA for dates only with a msg box on Sheet1.

Anyone help please?

Regards
Chris

Bob Phillips
03-28-2012, 03:32 PM
Try this worksheet event code


Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo ws_exit

Application.EnableEvents = False

With Target

If .Cells.Count = 1 Then

If .Column = 4 Or .Column = 5 Then

If .Row > 1 Then

If Not IsDate(.Value) Then

MsgBox "Not a date"
.Value = ""
End If
End If
End If
End If
End With

ws_exit:
Application.EnableEvents = True
End Sub