Actually I have led you up the garden path - if you write the code above and then place it into a cell it may be in wrong format. If you use the following then users can enter 3/4/12 or 03/04/12 or 3/4/2012
Private Sub txtdate_Exit(ByVal Cancel As MSForms.ReturnBoolean)
With txtdate
If Not IsDate(.Text) Then
MsgBox "You have not entered a valid date"
Else
.Text = CDate(.Text)
End If
End With
Cells(1, 1) = CDate(txtdate.Value)
End Sub
I would really recommend you look into using a Calendar Control - I have attached a simple form showing you how to use it - this way the date is always valid. Data entry should always be validated and a Calendar Control is the best way. The only catch is not everyone may have the calendar control on their machine - if Access is installed then the Calendar Control should be. If you Right click on Toolbox and then select Additional Controls and look for Calendar Control 12 (if you are using Excel 2007) you can add the control to the toolbox. If you cannot find the calendar control or have problems running the attached workbook with a simple form I will give you instructions on how to install the calendar control - it is very simple however anyone who uses the workbook with the calendar must have the calendar control for it to work.
Bookmarks