flyte
New Member
Hi Everyone and I hope your day is going well,
I have a report that holds around 100 pivot tables on different worksheets. I have coded to refresh all the pivot tables and change the page fields. I know the coding can be better. My way is just too long.
Example:
This code is against every page field (there are 5 page fields) against every pivot table in every worksheet(there are 7 Worksheets).
To clear the page fields I have used the following code:
Again the code is repeated over and over again against each Pivot table on each worksheet.
I know this is not in a hair's breath of being close to the best way to update multiple pivot tables on multiple worksheets. Can someone please direct me to the best approach?
Any hints and tips would be greatly appreciated. As I have to duplicate this report another 4 times.
Cheers
Tash
I have a report that holds around 100 pivot tables on different worksheets. I have coded to refresh all the pivot tables and change the page fields. I know the coding can be better. My way is just too long.
Example:
Code:
Private Sub ListBox1_Click()
Clear_All_Filters
Worksheets("Summary").Select
Worksheets("Summary").Range("I1").Value = "SELECTION BY HUB NAME"
Worksheets("Summary").Range("I2").Value = Me.ListBox1.Value
'Change Pivot Tables
' Income Management Page Pivot Table (P1 to P4)
MASTwb = ThisWorkbook.Name
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P1").PageFields("Hub Name").CurrentPage = Me.ListBox1.Value
MASTwb = ThisWorkbook.Name
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P2").PageFields("Hub Name").CurrentPage = Me.ListBox1.Value
MASTwb = ThisWorkbook.Name
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P3").PageFields("Hub Name").CurrentPage = Me.ListBox1.Value]
This code is against every page field (there are 5 page fields) against every pivot table in every worksheet(there are 7 Worksheets).
To clear the page fields I have used the following code:
Code:
Sub Clear_IM_Filters()
'Clear Pivot Tables - Income Management Sheet
MASTwb = ThisWorkbook.Name
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P1").PageFields("Hub Name").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P1").PageFields("Hub Group").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P1").PageFields("Parent Community").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P1").PageFields("Community").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P1").PageFields("Office").ClearAllFilters
MASTwb = ThisWorkbook.Name
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P2").PageFields("Hub Name").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P2").PageFields("Hub Group").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P2").PageFields("Parent Community").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P2").PageFields("Community").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P2").PageFields("Office").ClearAllFilters
MASTwb = ThisWorkbook.Name
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P3").PageFields("Hub Name").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P3").PageFields("Hub Group").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P3").PageFields("Parent Community").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P3").PageFields("Community").ClearAllFilters
Workbooks(MASTwb).Sheets("Income Management").PivotTables("P3").PageFields("Office").ClearAllFilters
End Sub
Again the code is repeated over and over again against each Pivot table on each worksheet.
I know this is not in a hair's breath of being close to the best way to update multiple pivot tables on multiple worksheets. Can someone please direct me to the best approach?
Any hints and tips would be greatly appreciated. As I have to duplicate this report another 4 times.
Cheers
Tash