Solved Filter on past one month date

suryu

Member
Local time
Today, 23:26
Joined
Apr 3, 2020
Messages
86
Working on lookup main file data from another workbook data contains order date

->lookup is only for last one month data , want to filter Order Date column for the past one month date format(ex- 06/10/2020 to 07/11/2020)
 
Hi anybody please help me on this:

i have column name Orderdate and i want to apply filter from last month till yesterday date
if today date is 07/18/20 then it should filter from 06/18/20 to 07/17/20


confused how to do autoflter
 
Hi anybody please help me on this:

i have column name Orderdate and i want to apply filter from last month till yesterday date
if today date is 07/18/20 then it should filter from 06/18/20 to 07/17/20


confused how to do autoflter
 
can you use Custom Filter to your column.
doesn't require any VBA.
 
can you use Custom Filter to your column.
doesn't require any VBA.
I am working on project which should open workbook and filter column on the given criteria using vba

thank you
 
Last edited:
What code have you tried so far after reading through Gasman's suggested article?
 
Code:
Private Sub Workbook_Open()
    'replace sheet1 with correct sheet to filter
    Sheet1.Select
    'replace Range("A1") and Range("A$1") with correct column to filter
    Range("A1").Select
    Selection.AutoFilter
    Range("$A$1").AutoFilter Field:=1, Criteria1:=">=" & VBA.Format(DateAdd("m", -1, Date), "m/d/yyyy"), Operator _
        :=xlAnd, Criteria2:="<" & VBA.Format(Date, "m/d/yyyy"), SubField:=0

End Sub
 
Code:
Private Sub Workbook_Open()
    'replace sheet1 with correct sheet to filter
    Sheet1.Select
    'replace Range("A1") and Range("A$1") with correct column to filter
    Range("A1").Select
    Selection.AutoFilter
    Range("$A$1").AutoFilter Field:=1, Criteria1:=">=" & VBA.Format(DateAdd("m", -1, Date), "m/d/yyyy"), Operator _
        :=xlAnd, Criteria2:="<" & VBA.Format(Date, "m/d/yyyy"), SubField:=0

End Sub
After removing SubField:=0, It is working fine ...thank you :)
 

Users who are viewing this thread

Back
Top Bottom