My goal is to refresh the pivot tables of a worksheet, when changes are done to some cells. These cells contain percentages which influence the pivot tables, and are the only cells that are edited.
This is the code I have so far, but when I run it, it gives me this error: “Run-time error ‘424’: Object required”, and it points to Line 4.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim PT As PivotTable
For Each PT In Worksheet.PivotTables
PivotTable.PivotCache.Refresh
Next PT
End Sub
I suspect it may be a syntax error, and some fault at my end, but I cannot figure it out.
I tried Refresh All, and it works of course, but I have multiple Querries in different sheets and only want to refresh all the pivot tables. At first I wrote PT as PivotTable, in the for-loop, thinking it was sufficient, but it gave me this error, after which I added Dim PT As PivotTable
, which did not solve the issue.