简体   繁体   English

Excel VBA-按日期筛选

[英]Excel VBA - filter by date

I'm trying to write a VBA to filter a file. 我正在尝试编写VBA来过滤文件。

I filtered it for Field 5 and 8 but i also want field 7 to filter for date - i want the file to show all lines that are today + 14 day and filter the rest. 我为字段5和8过滤了它,但我也希望字段7过滤日期-我希望文件显示今天+ 14天的所有行并过滤其余部分。

thanks 谢谢

Sub Filter()

'
   Sheets("CP").Select
    Range("a3:d" & Cells(Rows.Count, "e").End(xlUp).Row).AutoFilter Field:=5, Criteria1:="Plan"

 Range("a3:d" & Cells(Rows.Count, "e").End(xlUp).Row).AutoFilter Field:=18, Criteria1:="No"

End Sub

Please try. 请试试。

Range("a3:d" & Cells(Rows.Count, "e").End(xlUp).Row).AutoFilter Field:=7, 
Criteria1:=">=" & Date(), Operator:=xlAnd, Criteria2:="<" & Date() +14

i added 我加了

' Range("a3:d" & Cells(Rows.Count, "e").End(xlUp).Row).AutoFilter Field:=7, 'Range(“ a3:d”&Cells(Rows.Count,“ e”)。End(xlUp).Row).AutoFilter Field:= 7,

Criteria1:="<=" & Date + 14, Operator:=xlAnd, Criteria2:="<" & Date + 14 ' Criteria1:=“ <=”&Date + 14,'运算符:= xlAnd,Criteria2:=“ <”&Date + 14'

it seems to work. 它似乎有效。

thanks 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM