Forum Discussion
VBA Code for Pivot Table refresh
Right-click the sheet tab of the Sales Hygiene Pivot sheet.
Select View Code from the context menu.
Copy the following code into the worksheet module:
Private Sub Worksheet_Activate()
Me.PivotTables(1).PivotCache.Refresh
End Sub
This will update the pivot table each time you switch to the Sales Hygiene Pivot sheet to view the pivot table.
Do the same for the other sheets with pivot tables.
HansVogelaar Hey man! Thank you for the help. But the code says the reference is not valid. Do I need to change Me. PivotTables(1) to Me. PivotTables(2) and then (3) for the next pivot table sheets to make the code work?
- HansVogelaarApr 01, 2024MVP
Did you right-click the sheet tab of a sheet with a pivot table?
It won't work if you right-click the sheet tab of a sheet with the source data for a pivot table.
- TawfiqMugdhaApr 02, 2024Copper Contributor
HansVogelaar Yeah! I did write the code for the sheets that have Pivot Tables
- HansVogelaarApr 02, 2024MVP
Could you attach a small sample workbook demonstrating the problem (without sensitive data), or if that is not possible, make it available through OneDrive, Google Drive, Dropbox or similar?