ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Date Formatting (https://www.excelbanter.com/excel-programming/284277-date-formatting.html)

S. S.

Date Formatting
 
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.

Dianne

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.





All times are GMT +1. The time now is 03:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com