Consulting

Results 1 to 2 of 2

Thread: Date validation in VBA

  1. #1

    Date validation in VBA

    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this worksheet event code

    [vba]
    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[/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •