VBA Excel自动过滤器在当前月份之前的任何日期 [英] VBA Excel autofilter for any date before the current month

查看:849
本文介绍了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

这篇关于VBA Excel自动过滤器在当前月份之前的任何日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆