Autofilters

markbarr

New member
Joined
Aug 24, 2013
Messages
7
Reaction score
0
Points
0
Hi Guys

i'm using the following to autofilter a field by month
Code:
Worksheets("Master").Range("$A:$AB").AutoFilter Field:=5, Criteria1:=xlFilterAllDatesInPeriodJuly, Operator:=xlFilterDynamic

this works perfect if all the data in the master sheet is from the same year

what I need to do is specify the month and the year so that it only returns records that are from a specific month and a specific year

The field number 5 has a date and time in it in the following format

"03/07/2013 10:47:56"

i need to set a variable as follows

Code:
reportmonth = "7" ;EG July
reportyear = "2013"

I cant for the life of me work out how to specify the two criteria and return the correct number of records

any ideas

mark
 
Last edited by a moderator:
Try recording a macro while manually doing the same filtering.... it should give you an idea.
 
Don't know how you are going about determining what month to filter on but if you have a look here you will be able to have variables for the 1st of the month and the last of the month and then use

Code:
Worksheets("Master").Range("$A:$AB").AutoFilter Field:=5, Criteria1:=">=" & StartDate, Operator:=xlAnd, Criteria2:="<=" & EndDate
 
Back
Top