Thread: Date Formatting
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dianne Dianne is offline
external usenet poster
 
Posts: 107
Default Date Formatting

Maybe something like this?

Sub Test()

Dim Answer As String

Answer = Trim(InputBox("Enter date in DD-MM-YY format"))
If Answer = "" Then Exit Sub
If Not IsDate(Answer) Then
MsgBox "Invalid Date!"
Exit Sub
End If
If Mid(Answer, 3, 1) < "-" Or _
Mid(Answer, 6, 1) < "-" Or Len(Answer) < 8 Then
MsgBox "You must use 2 digits for day, month and year" _
& " and you must use hyphen (-) as the separator"
Exit Sub
End If

End Sub

--
HTH,
Dianne

In ,
S. S. typed:
Is there a way to specify that a Date format can only be
in MM-DD-YY, not MM/DD/YY?

If Answer = "" Then Exit Sub
If Not IsDate(Answer) Then
MsgBox "Invalid Date!"
Exit Sub
End If

This will confirm that it is a date, but won't distinguish
between / and -.

Thanks

S.