Excel VBA - filter by date

╄→гoц情女王★ 提交于 2020-01-06 05:37:05

问题


I'm trying to write a VBA to filter a file.

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.

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

回答1:


Please try.

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



回答2:


i added

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

Criteria1:="<=" & Date + 14, Operator:=xlAnd, Criteria2:="<" & Date + 14 '

it seems to work.

thanks



来源:https://stackoverflow.com/questions/48522990/excel-vba-filter-by-date

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!