Filtering Pivot Table by Dates up to Today

WhollyUnqualified

New Member
Joined
Mar 21, 2016
Messages
4
I have a single, large (about 17K lines) data export from a database which populates about a dozen pivot tables. Most of these are primarily filtered by a "Required Date" column, which changes daily.

I need to select the current date and all dates in the past, which up until now has involved a great deal of manual "clicking" on my part. I am attempting to automate this process using VBA code, but am having issues figuring out how to select all dates (in my "Required Date" field) up to AND including TODAY.

Any suggestions would be greatly appreciated. Thanks!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Wholly...

The following might get you started...

Code:
Sub FilterPivotTableDate()
    Dim ws As Worksheet
    Dim pt As PivotTable
    Dim d8te As Date
    
    Set ws = ActiveSheet
    d8te = Date
    
    For Each pt In ws.PivotTables
        pt.PivotFields("Required Date").ClearAllFilters
        pt.PivotFields("Required Date").PivotFilters.Add _
            Type:=xlBeforeOrEqualTo, Value1:=d8te
    Next pt
End Sub

Cheers,

tonyyy
 
Upvote 0
Tonyyy,
Thanks for your help! I had a heck of a time getting it to work, until some research pointed me to the fact that the .PivotFilters.Add function does not work when the filter is in the Report Filter field. I needed to move "Required Date" to the Row Labels field, and the code you provided worked great.

Thanks again!

WhollyUnqualified
 
Upvote 0
You're welcome. Glad it worked out...
 
Upvote 0

Forum statistics

Threads
1,215,945
Messages
6,127,861
Members
449,411
Latest member
adunn_23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top