ateneva
4/22/2017 - 12:09 PM

Refilter pivot tables that have different pivot caches (come from different sources)

Refilter pivot tables that have different pivot caches (come from different sources)

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