Solved Filtering data for current month and days that have passed

December 2, 2016 at 05:42:27
Specs: Windows 7
Excel experts, thank you for all your support this year. I have another request:

I have a date field in excel that I would like to filter for only if the date falls in the current month AND if the date is today or in the past.

So for example today is the 2nd so the filter would show me any row that is equal to today or yesterday.

This is the filter I currently have, it filters out if the cell falls in the current month only, so it shows me rows that are in the future for the current month, what tweak do I need to accomplish my request?

ActiveSheet.Range("$A$6:$EX$1000").AutoFilter Field:=31, _
           Criteria1:=Array("="), Operator:=xlFilterValues, Criteria2:=Array(1, Now)


See More: Filtering data for current month and days that have passed

Report •

#1
December 2, 2016 at 10:38:02
✔ Best Answer
    dDate = DateSerial(Year(Date), Month(Date), 1)
      Range("A1").AutoFilter Field:=1, Criteria1:=">=" & dDate, _
                      Operator:=xlAnd, Criteria2:="<=" & Date

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#2
December 2, 2016 at 12:04:31
Since you seem to do a lot of filtering based on dates, maybe this page will help you:

"XlDynamicFilterCriteria enumeration"

https://msdn.microsoft.com/en-us/li...

It interesting that they have xlFilterThisMonth and xlFilterThisYear and xlFilterYearToDate but they don't have an xlFilterMonthToDate.

That seems like something people would track, so why not make it easy?

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#3
December 4, 2016 at 17:57:55
Thanks for always helping me, I read the link you sent and found it useful, it is odd that MTD is not an option.

Report •
Related Solutions


Ask Question