Check for format in form field

N

Nigel

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
 
O

Otto Moehrbach

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top