Forum Discussion
TawfiqMugdha
Apr 01, 2024Copper Contributor
VBA Code for Pivot Table refresh
Hello everyone! I have this code, that refreshes all the pivot tables in the workbook. Private Sub Worksheet_SelectionChange(ByVal Target As Range) Dim p As PivotCache For Each p In This...
TawfiqMugdha
Apr 01, 2024Copper Contributor
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?
HansVogelaar
Apr 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?