Assign new pivot cache to a pivot table

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Looking here. I'm not sure how to make sure that I'm choosing the right pivot cache though. Is it possible to check the source range of a pivot cache that refers to a worksheet range?

Edit: Also, I don't actually see this method available for VBA's PivotTable object or for indexed members of the PivotTables collection. Is this only available in VB?
 
Upvote 0
Code:
MsgBox ActiveSheet.PivotTables(1).PivotCache.SourceData
This successfully returns a range on the source sheet... but it's much smaller than the actual source range (which has something like ten thousand rows in it).

The exact return text reads:

'Sheet1'!C1:C10


Code:
ActiveSheet.PivotTables(1).PivotCache.SourceData = _
    "'Sheet2'!A1:J65536"

Tried this, but it gives error 1004, pivot table item not valid.

Edit: The sourcedata property is read/write.
 
Upvote 0
I don't really understand it at all. I hope this is helpful to you.

Code:
Sub ChangePivotCache()
'pivot table tutorial by contextures.com
'change pivot cache for all Pivot Tables in workbook
Dim pt As PivotTable
Dim wks As Worksheet
 
For Each wks In ActiveWorkbook.Worksheets
For Each pt In wks.PivotTables
pt.CacheIndex = Sheets("Pivot").PivotTables(1).CacheIndex
Next pt
Next wks
 
End Sub
found at
http://www.contextures.com/xlPivot11.html
 
Upvote 0
I'm having to work with a lot of rows of data; more than the maximum limit for a single sheet. Instead of creating a new pivot table every time I have to create a new data sheet, it seemed like there must be a way to switch the source of the pivot tables I'm already using.

You just tracked it down. Thanks.
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,762
Members
452,940
Latest member
rootytrip

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