Hi,
I’m trying to get the macro below to refresh all the pivot tables in the workbook upon exiting the “Data” worksheet. It works kind of works, but is NOT refreshing one of the pivot tables on one of the worksheets. It seems to only refresh the pivot table located in the worksheet I click on directly upon exiting the “Data” worksheet (actually it seems to refresh 3 pivot tables on 3 different worksheets, however it skips one pivot table, which is also on it’s own worksheet). I’ve also checked, and all 4 of the pivot tables are named PivotTable1. I’m assuming it’s having a problem because of the “activesheet” part of the macro?? Help!?!?!
Thanks!
Lana
Private Sub Worksheet_Deactivate()
Dim wsh As Worksheet
Dim lngRow As Long
‘Clear zeros out of the summary lines & detail lines in the Data worksheet upon exiting the Data worksheet
With Worksheets(“Data”)
For lngRow = 1 To .Range(“A65536”).End(xlUp).Row
If UCase(.Range(“A” & lngRow)) = “S” Then
.Range(“R” & lngRow & “:Z” & lngRow).ClearContents
.Range(“AH” & lngRow & “:AT” & lngRow).ClearContents
End If
If UCase(.Range(“A” & lngRow)) = “D” Then
.Range(“AA” & lngRow & “:AE” & lngRow).ClearContents
End If
Next lngRow
End With
‘Refresh all pivot tables in every worksheet in the workbook upon exiting the Data worksheet
For Each wsh In Worksheets
ActiveSheet.PivotTables(“PivotTable1”).PivotCache.refresh
Next wsh
End Sub