Andres:
It doesn't matter how they enter the date, simply format the cells to display it the way you want it to be seen.
lenze
I'm really sorry but I'm not following you Lenze.
I dont understand the Cell stuff.
On second thought, this is true assuming you are talking about current dates between 1930 and 2029. If outside this range, you may have to format your cells as text and then use data validation to limit the length to between 8 and 10 characters. You will then have to use the DateValue function to perform your calculations. I'm also sure someone can suggest a VBA code to require proper entry
lenze
I'm assuming your talking about a UserForm with textboxes, if so try the code below. It requires a Userform, TextBox1, Textbox2 and CommandButton1
Option Explicit
Dim DateCheck2 As Date
Dim DateCheck1 As Date
Private Sub CommandButton1_Click()
MsgBox DateDiff("d", DateCheck2, DateCheck1)
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox1) Then
MsgBox "Your date is not valid, please correct it.", vbCritical, "OzGrid Business Applications"
Cancel = True
Else
DateCheck1 = TextBox1.Value
TextBox1 = Format(TextBox1, "dd/mm/yyyy")
End If
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsDate(TextBox2) Then
MsgBox "Your date is not valid, please correct it.", vbCritical, "OzGrid Business Applications"
Cancel = True
Else
DateCheck2 = TextBox2.Value
TextBox2 = Format(TextBox2, "dd/mm/yyyy")
End If
End Sub
OzGrid Business Applications