Place this macro in the sheet module of your sheet. To access that module,
right-click on the sheet tab and select View Code. Paste this macro into
that module. "X" out of the module to return to your sheet. As written,
this macro will react to any entry in Column J. Change that as needed.
This macro doesn't check for date format, just if it's a date or not. If it
is, the macro will format the cell as you wanted. HTH Otto
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > 1 Then Exit Sub
If IsEmpty(Target.Value) Then Exit Sub
If Not Intersect(Target, Columns("J:J")) Is Nothing Then
Application.EnableEvents = False
If IsDate(Target.Value) Then
Target.NumberFormat = "[$-409]d-mmm-yyyy;@"
Else
MsgBox "The entry is not a valid date.", 16, "Invalid
Entry"
Target.ClearContents
End If
Application.EnableEvents = True
End If
End Sub
"Nigel" <(E-Mail Removed)> wrote in message
news:F84A0AEC-09C1-42FE-A267-(E-Mail Removed)...
>I have a form that a user will fill out and then update a spreadsheet, one
>of
> the fields is for Date of Birth, I would like to be able to force the
> field
> to only accept the data in a certain way
>
> dd-mm-yyyy or to force the field to be a date field
>
> is there any way to accomplish this
>
> thanks
|