Autofilter with column formatted as date

前端 未结 10 1710
遥遥无期
遥遥无期 2020-11-27 21:58

I am using an AutoFilter with VBA in Excel that works for regular filters, but not a column formatted as date.

I can filter it manually. If I run my code, it filters

10条回答
  •  执念已碎
    2020-11-27 22:15

    Dates can be tricky with Excel VBA AutoFilter. Some find it easier to just loop through the array to be filtered.

    Sometimes I have found that one can use the numeric value of the date, especially when dealing with "dates between"

    Criteria1:= ">" & CDbl([datecell])
    Criteria2:= "<=" & CDbl(WorksheetFunction.EoMonth([datecell], 3))
    

    Note that the above need to be "real dates" and not strings that look like dates. Even a single "string date" will mess things up.

提交回复
热议问题