• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Pivot cache update

sms2luv

Member
Hi
I have a normal table(a) which gets data using getpivotdata
From other 4 pivot table

I made a new pivot from the normal table(a).
I am using below VBA code to refresh all pivot tables.
Code:
Private Sub refreshdata_Click()

Dim PC As PivotCache

For Each PC In ActiveWorkbook.PivotCaches

PC.refresh

Next PC

End Sub

When I run this code once the pivot does not gets updated and have to run the code twice.
I think that the code is first refreshing table(a) pivot and then its refreshing other 4 pivots.

In short I have a pivot table which is based on other pivot table.
Please help
 
I suggest you either just add a second loop, or specifically refresh the pivot cache for the new pivot table again at the end.
 
Either just repeat the code you have, or refresh the pivot table by name - for example:

Code:
Sheets("sheet name here").Pivottables("pivot table name here").RefreshTable
 
Hi
I tried the below code and got run time error.

Code:
PrivateSub refreshdata_Click()

Dim PC As PivotCache

Dim I as integer
For I = 1 to 3
ForEach PC In ActiveWorkbook.PivotCaches

PC.refresh

Next PC
Next i
EndSub

Also tried still got error
Code:
PrivateSub refreshdata_Click()

Dim PC As PivotCache
Sheets("pivot").Pivottables("pivottable2").refreshtable
ForEach PC In ActiveWorkbook.PivotCaches

PC.refresh

Next PC

EndSub
 
What error? I assume the missing spaces in the code you posted are present in your actual code?
 
Back
Top