Update Date Filter for Multiple Pivot Tables Simultaneously

Status
Not open for further replies.

npetrisis

New Member
Joined
Jun 18, 2015
Messages
3
I have about 10-15 pivot tables that I would like to apply a date filter to based on a date range. I have a script for a macro that will do this when the date is classified as a pivot field in the row labels section of the pivot table, and it will read the start value (cell H1) and end value (cell H2) for the dates I want and apply this filter accordingly. This is the script:

With ActiveSheet.PivotTables("PivotTable1")
' Remove any existing filter
.ClearAllFilters
' Add a filter for the date range
.PivotFields("Date").PivotFilters.Add Type:=xlDateBetween, _
Value1:=CStr(Range("H1")), Value2:=CStr(Range("H2"))
End With

However, when date is moved to the Report Filter field in the pivot tables, this script will not work because date is not recognized as a pivot field. I get the error "Run-time error 1004: Application-defined or object-defined error". My pivot tables are designed with the date in the Report Filter, so is there a way to apply this date range filter logic so that all my tables will be impacted simultaneously?

Thanks
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Status
Not open for further replies.

Forum statistics

Threads
1,214,643
Messages
6,120,702
Members
448,980
Latest member
CarlosWin

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