检查vba excel 2010 64位中的特定日期格式

时间:2021-08-23 17:34:57

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.

我正在对用户输入日期值的单元格进行一些验证。我期待的正确格式是“m / d / yyyy”,所以我需要一种方法来检查用户是否以该格式输入日期。

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

1 个解决方案

#1


0  

Siddharth Rout's solution:

Siddharth Rout的解决方案:

Hope this helps? support.microsoft.com/kb/211485.

希望这可以帮助? support.microsoft.com/kb/211485。

#1


0  

Siddharth Rout's solution:

Siddharth Rout的解决方案:

Hope this helps? support.microsoft.com/kb/211485.

希望这可以帮助? support.microsoft.com/kb/211485。