What is the nature of Pivot Cache; Data Source Drift

CongoGrey

New Member
Joined
Jul 5, 2011
Messages
23
A Good Morning to All:
I am working in Excel 2010. I created a workbook for distribution where the user will make a copy of the workbook posted in a central location, then paste the copy a local area of their own choosing.

With the workbook I have several functions which work the same. I am pulling data from an Oracle system (VBA string) and writing it to a sheet ("Table1_Sheet" containing the named range "tbl_Table1"). I then manually created a pivot table in a second sheet (PivotTbl1_Sheet containing the named range "pvt_Table1"). On subsequent Oracle downloads, which I trigger by clicking on a button on Table1_Sheet, I refreshed the pivot using the following line of code:

ActiveWorkbook.Worksheets("PivotTbl1_Sheet").PivotTables("pvt_Table1").PivotCache.Refresh

This worked so well that I used it to download, create table, refresh pivot for several different datasets. I then started to make copies of the workbook and here's the rub. In copies, the named table is local, but when I try to refresh the pivot cache the data source cannot be located. When I go to the sheet where the pivot is and look at the datasource, the pivot is pointing back--not to the sheet that I copied from--but to the sheet it was originally created on.

I don't know what to do. What is the nature of pivot cache? Do I need to "set" something?

Any suggetions will be most gratefully received. I am self taught knowing some things well while also being unaware of others.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
The solution was-

add this line:

ActiveWorkbook.Worksheets("PivotTbl1_Sheet").PivotTables("pvt_Table1").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:="tbl_Table1", _
Version:=xlPivotTableVersion14)

retain this line:

ActiveWorkbook.Worksheets("PivotTbl1_Sheet").PivotTables("pvt_Table1").PivotCache.Refresh

seems to be working over multiple cuts/pastes/moves etc.

CongoGrey
 
Upvote 0
A further enhancement was-

With Sheet_Data_PivotTabl1_Sheet.PivotTables("pvt_Table1")
.ChangePivotCache ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=tbl_Table1Table_Name)
.PivotCache.Refresh
End With

these lines use variables.

CongoGrey
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,703
Members
452,938
Latest member
babeneker

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