[英]VBA Excel autofilter for any date before the current month
I'm trying to filter a date column for any date that falls before the 1st of the current month. 我正在尝试过滤日期列以查找当前月1日之前的任何日期。 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. 但不包括它运行的当月的任何日期。
Edit: 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.
如果现在应用了过滤器,则仅显示日期为2015年1月。如果应用了8月,则仅显示的可见日期应为2015年1月至7月之间的任何日期。
This should work for you: 这应该为您工作:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.