I'm doing some validations to a cell where the user inputs a date value. The correct format I'm expecting is "m/d/yyyy", so I need a way to check that the user enter the date in that format.
How can I achieve that?
here are some of the validations I've made:
Dim StartDate As String
Dim EndDate As String
With Sheet1
StartDate = WorksheetFunction.Trim(.Range("F2").Value)
EndDate = WorksheetFunction.Trim(.Range("F3").Value)
End With
'Dates validations
If StartDate = "" Or EndDate = "" Then
MsgBox ("Dates can't be empty")
Exit Sub
End If
If Not IsDate(StartDate) Or Not IsDate(EndDate) Then
MsgBox ("Please check dates format")
Exit Sub
End If
If CDate(StartDate) > CDate(EndDate) Then
MsgBox ("Start Date can't be greater than End Date")
Exit Sub
End If
Siddharth Rout's solution:
Hope this helps? support.microsoft.com/kb/211485 .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.