vba refresh and sort pivot table code example Example: vba refresh pivot table Private Sub Worksheet_Deactivate() ThisWorkbook.RefreshAll End Sub