Last active
April 22, 2018 08:45
-
-
Save ateneva/ca18dad5a1c647df5ef716ec4747e9a9 to your computer and use it in GitHub Desktop.
Refilter pivot tables that have different pivot caches (come from different sources)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Sub Workbook_AfterSave(ByVal Success As Boolean) | |
Dim Wks As Worksheet | |
Dim PT As PivotTable | |
Dim PF As PivotField | |
Dim Ans As String | |
Dim Ans2 As Integer | |
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
'written by Angelina Teneva 2013 | |
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
Worksheets("CostsAnalysis").Activate | |
Ans2 = MsgBox("Would you like to refilter pivot tables", vbYesNo) | |
Select Case Ans2 | |
Case vbYes | |
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
'apply filter for the latest month to all pivot tables | |
Ans = InputBox("Please enter latest fiscal period in the format Period nn yyyy") | |
For Each Wks In ThisWorkbook.Worksheets | |
If Wks.PivotTables.Count > 0 And Wks.Name <> "Presales Costs" _ | |
And Wks.Name <> "Costs Trend" And Wks.Name <> "# Details" Then Wks.Activate | |
For Each PT In ActiveSheet.PivotTables | |
Set PF = PT.PivotFields("Fiscal year/period") | |
On Error Resume Next | |
PF.ClearAllFilters | |
PF.EnableMultiplePageItems = False | |
PF.CurrentPage = Ans | |
Next PT | |
Next Wks | |
Case vbNo | |
MsgBox ("Remember to re-filter before closing") | |
End Select | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment