VBA Excel自动过滤器在当前月份之前的任何日期

问题描述:

我正在为当前月份之前的任何日期过滤日期列。
那么类似于以下的东西:

I'm trying to filter a date column for any date that falls before the 1st of the current month. So something similar to below:

ActiveSheet.Range("$A:$BF").AutoFilter Field:=12, Criteria1:= _
    xlFilterYearToDate, Operator:=xlFilterDynamic

但不包括任何日期在当前月份运行。

But doesnt include any dates in the current month it runs on.

编辑:
所有任何在当前月份之前的日期。如果现在应用了过滤器,它将只显示2015年1月的日期。如果在8月份应用,只有生成的可见日期应该是2015年1月至7月之前的任何内容。

So any date that falls before the first of the current month, within the current year. If the filter was applied now, it would only show dates with the month of January 2015. If applied In August, only resulting visible dates should be anything within January-July 2015.

这应该适合你:

Dim dtStart As Date
Dim dtFinal As Date

dtStart = CDate(Evaluate("DATE(YEAR(NOW()),1,1)"))
dtFinal = CDate(Evaluate("EOMONTH(TODAY(),-1)"))

ActiveSheet.Range("A:BF").AutoFilter 12, ">=" & dtStart, xlAnd, "<=" & dtFinal