Refresh PT Problem

mikeymay

Well-known Member
Joined
Jan 17, 2006
Messages
1,600
Office Version
  1. 365
Platform
  1. Windows
I have a number of pivot tables in different worksheets but all connected to the same data and data range.

All of these sheets are protected and upon a sheet being activates (Worksheet_Activate) the sheet is unprotected and the table in that sheet is refreshed.

This works perfectly well for one sheet when I only unprotect the active sheet but on all the other worksheets, I have to unprotect ALL worksheets that have a pivot table connected to the same data.

I can see that I need to unprotect all worksheets to update a pT but I can't work out why one of the worksheets doen't need all the other worksheets unprotecting.


TIA
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
It sounds like you actually have two pivot caches.
 
Upvote 0
The one that doesn't need all unprotecting is based on the same dataset but it was created prior to other columsn being added to the dataset.

The dynamic range used in this pt is the same as all the others though.
 
Upvote 0
That doesn't change what I said. :) What does Msgbox activeworkbook.pivotcaches.count display if you run it from the immediate window in the VB Editor? 2?
 
Upvote 0
OK, and how many different data sets do you think are in use for pivot tables in the workbook?
 
Upvote 0
Then it looks like either this is an old file (Excel used to default to a separate cache per pivot unless you said otherwise) or something odd happened when the pivot tables were being created as you apparently have 7 different data caches.
 
Upvote 0
Its a file I created in 2019.

Is it possible to clear all the caches or direct the tables to just one?
 
Upvote 0
You could run something like this - just change the ptMaster reference to any pivot table that you are sure is using the correct range:

Code:
Sub resetPivots()
    Dim ptMaster As PivotTable
    Set ptMaster = Sheets("Sheet5").PivotTables(1)
    
    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
        Dim pt As PivotTable
        For Each pt In ws.PivotTables
            If Not pt.Name = ptMaster.Name Then
                pt.CacheIndex = ptMaster.CacheIndex
                pt.RefreshTable
            End If
        Next pt
    Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,375
Messages
6,124,578
Members
449,174
Latest member
chandan4057

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top