title | keywords | f1_keywords | api_name | ms.assetid | ms.date | ms.localizationpriority | ||
---|---|---|---|---|---|---|---|---|
PivotTable.ChangePivotCache method (Excel) |
vbaxl10.chm235184 |
|
|
1b1ee1b4-0ed6-641a-3e1d-739461fa0466 |
05/08/2019 |
medium |
Changes the PivotCache object of the specified PivotTable.
expression.ChangePivotCache (bstr)
expression A variable that represents a PivotTable object.
Name | Required/Optional | Data type | Description |
---|---|---|---|
bstr | Required | String | A PivotTable or PivotCache object that represents the new PivotCache for the specified PivotTable. |
The ChangePivotCache method can only be used with a PivotTable that uses data stored on a worksheet as its data source. A run-time error occurs if the ChangePivotCache method is used with a PivotTable that is connected to an external data source.
In the following code sample, the pivot table named PivotTable1 is on Sheet1. The code changes its pivot cache to a cache created from the data stored in the table called Table2 in the same workbook.
Sheets("Sheet1").PivotTables("PivotTable1").ChangePivotCache _
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:="Table2", Version:=xlPivotTableVersion15)
[!includeSupport and feedback]