Hi,
I'm new to VBA and I'm trying to write a simple procedure to alter the filter selections on a Pivot table using VBA.
I am successful in manipulating the page fields (Pivot Filters) on the pivot using the following code, but have no idea on how to manipulate the column or row label field filters on the same table.
Here is the code I have written so far and the Bold statement is the one I'm having trouble with:
Public Sub Business()
Application.ScreenUpdating = False
Sheets("Global 360").PivotTables("G360").PivotFields("Line Director").CurrentPage = Sheets("2011 Summary").Range("V5").Value
Sheets("Chart Data").PivotTables("chart").PivotFields("Line Director").CurrentPage = Sheets("2011 Summary").Range("V5").Value
Sheets("Chart Data").PivotTables("chart").PivotFields("Site").CurrentPage = Sheets("2011 Summary").Range("U5").Value
Sheets("Top 20").PivotTables("top20").PivotFields("Line Director").CurrentPage = Sheets("2011 Summary").Range("V5").Value
Sheets("Top 20").PivotTables("total").PivotFields("Line Director").CurrentPage = Sheets("2011 Summary").Range("V5").Value
Sheets("CF Pivot").PivotTables("CFSite").PivotFields("Line Director").CurrentPage = Sheets("2011 Summary").Range("V5").Value
Sheets("CF Pivot").PivotTables("CFCat").PivotFields("Line Director").CurrentPage = Sheets("2011 Summary").Range("V5").Value
Sheets("Top 20").PivotTables("SiteG360").PivotFields("Line Director").CurrentPage = Sheets("2011 Summary").Range("V5").Value
Sheets("Top 20").PivotTables("SiteG360").PivotFilter("Site").DataField = Sheets("2011 Summary").Range("U5").Value
Sheets("Top 20 Issues").PivotTables("Top").PivotFields("Site").CurrentPage = Sheets("2011 Summary").Range("U5").Value
Sheets("Top 20 Issues").PivotTables("Top").PivotFields("Line Director").CurrentPage = Sheets("2011 Summary").Range("V5").Value
Sheets("Chart Data").PivotTables("chart").PivotFields("OM").CurrentPage = "All"
Sheets("Top 20").PivotTables("top20").PivotFields("OM").CurrentPage = "All"
Sheets("Top 20").PivotTables("total").PivotFields("OM").CurrentPage = "All"
Sheets("Top 20").PivotTables("SiteG360").PivotFields("OM").CurrentPage = "All"
Application.ScreenUpdating = True
End Sub
Here is a snapshot of the pivot table:
OM (All)
Line Director (All)
Count of Issue Site = Column Label / Filter
Month Albuquerque Boise Chennai Florence Gray Greensboro
Jan-11
Feb-11
Mar-11
Apr-11
May-11
The error line is in Bold Typeface, the rest of the code works well!
Any help on how I can update the column filter based on a value that is on another cell/sheet just like the page fields is what I'm looking for, and would be greatly appreciated!
Thanks,
Abhi
Bookmarks