Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatically update Pivot Tables

Status
Not open for further replies.

KymC

IS-IT--Management
Feb 17, 2003
2
AU
I have tried to use the code below to update a number of Pivot tables in a workbook.

However I get the error message "Reference is not valid" when the macro gets to the code "pt.refreshTable".

I have tried different statements but still not able to get past this error - any ideas out there?

Thanks for the help.

Cheers

Kym



Sub RefreshAllPivots()
Dim wks As Worksheet
Dim pt As PivotTable

With Application
.Calculation = xlAutomatic
End With
With Application
.Calculation = xlManual
End With

For Each wks In Worksheets
For Each pt In wks.PivotTables
pt.RefreshTable
Next pt
Next wks

With Application
.Calculation = xlAutomatic
End With
End Sub
 
Skip,
Thanks for that suggestion, it switched my brain on and started me thinking.

I had it in a module but moved it to the workbook object and it worked fine.

Thanks for the help.

Cheers
Kym
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top