Does anyone know the VBA code to automatically refresh all Pivot tables (2 sheets that each hold 4 pivot tables) when data in the Excel (2010) spreadsheet is changed? It can also search for change in a specific cell.
Any advice is welcome!
this code added to the worksheet containing the source data should work
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Sheet As Worksheet, Pivot As PivotTable
For Each Sheet In ThisWorkbook.Worksheets
For Each Pivot In Sheet.PivotTables
Pivot.RefreshTable
Pivot.Update
Next
Next
End Sub
For more info check http://msdn.microsoft.com/en-us/library/office/ff839775(v=office.15).aspx
If you have data in the sheet called "data" and table is in sheet "pivot" with table named "PivotTable1", you can paste this on your data sheet vba tab.
Private Sub Worksheet_Calculate()
'If data on this worksheet changes, refresh the pivot table
Sheets("Pivot").PivotTables("PivotTable1").RefreshTable
End Sub