I got this code in a question here, to update the dynamics of a worksheet, but when running the macro, it presents error - pt.RefreshTable
.
Run-time error '1004': Reference is not valid. (pt.RefreshTable)
Private Sub Worksheet_Activate()
'Dimensionar variáveis
Dim pt As PivotTable
Dim ws As Worksheet
'Atualiza Pivot Tables uma a uma
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.RefreshTable
Next pt
Next ws