Excel 2013. I am using 3 combo boxes to change filters on the pivot table. My first combo box has "Project1", "Project2" & All. My second combo box has "Customer1", "Customer2" & All. My third combo box has "Country1", "Country2" & All.
I am using 9 pivot tables, all of them have filters as [Project], [Customer], [Country].
My intention is to change first combo box to Project1 & all the pivot tables filter should change as Project1.I am successfully able to do that.
However when I select the first combo box as "All". First Combo box cell link to Y1. I get VBA Run time error 1004: Application-defined or object-defined error.
Sub ProjectName()
ActiveSheet.PivotTables("PVT1").PivotFields("Project Name").ClearAllFilters
ActiveSheet.PivotTables("PVT2").PivotFields("Project Name").ClearAllFilters
ActiveSheet.PivotTables("PVT3").PivotFields("Project Name").ClearAllFilters
ActiveSheet.PivotTables("PVT1").PivotFields("Project Name").CurrentPage = Range("Y1").Text
ActiveSheet.PivotTables("PVT2").PivotFields("Project Name").CurrentPage = Range("Y1").Text
ActiveSheet.PivotTables("PVT3").PivotFields("Project Name").CurrentPage = Range("Y1").Text
Since the first three lines of code go without issue, I will assume that the Pivot Table
PVT1
and the FieldProject Name
all exist. This places the error somewhere after that.For the call to
.CurrentPage
you will get a 1004 error for the following reasons:Report Filter
. You cannot use theCurrentPage
to filter any rows or columnsOn the second point, this is where the call to
Range
might be relevant..Text
which will use the display value of the cell and not its underlying.Value
To resolve these issues, there are a couple of options:
PivotItems
and setVisible = True/False
CurrentPage
, you can iterate thePivotItems
for thatPivotField
and check that one matches. The code for that is very similar to theFor Each
loop with the check on value, just don't setVisible
.Code for setting a filter on a row or column
Picture of ranges