Hi,

I have a pivot table and pivot chart on my spreadsheet. I need it to automatically refresh if the filter is changed.

I have tried the following code but none work. One of the codes only works if I click off and then back on to the sheet where the pivot table is.

Private Sub Worksheet_Activate()
     'If this worksheet is activated, refresh the pivot table
     'Change "Pivot" to your sheet's name
     'Change "PivotTable1" to your pivot table's name
     
    Sheets("UserSheet").PivotTables("PivotTable1").RefreshTable
     
End Sub

Sub RefreshAllPivots()
   Dim PC As PivotCache
   For Each PC In ActiveWorkbook.PivotCaches
      PC.Refresh
   Next PC
End Sub


Private Sub Worksheet_Change(ByVal Target As Range)
    Application.EnableEvents = False
    Me.PivotTables("PivotTable1").PivotCache.Refresh
    Application.EnableEvents = True
End Sub
Any suggestions?