大于或等于date条件

为什么在这个大于或等于条件不起作用。

Dim start As String Dim endat As String start = InputBox("Enter the Starting Date: Format: dd-mon-yy") endat = InputBox("Enter the End Date: Format: dd-mon-yy") Sheets("Data Base").Range("A1:H2000").AutoFilter Field:=5, Criteria1:=">=" & start, Operator:=xlAnd, Criteria2:="<=" & endat 

如果“数据库”表中列E中的值被格式化为Date ,则可以强制InputBox仅允许date格式。

使用Application.InputBoxFormatDateTime函数一起,将强制用户以date格式input。

要了解有关FormatDateTime MSDN的更多信息

 Option Explicit Sub BetweenDates() Dim StartDate As Date Dim EndDate As Date Do StartDate = Application.InputBox("Enter the Starting Date:", "Format: dd-mm-yyyy", FormatDateTime(Date, vbShortDate), Type:=1) Loop While StartDate = False ' disable the Cancel option Do EndDate = Application.InputBox("Enter the End Date:", "Format: dd-mm-yyyy", FormatDateTime(Date, vbShortDate), Type:=1) Loop While EndDate = False ' disable the Cancel option Sheets("Data Base").Range("A1:H2000").AutoFilter Field:=5, Criteria1:=">=" & StartDate, Operator:=xlAnd, Criteria2:="<=" & EndDate End Sub