PivotTable.ChangePivotCache method (Excel)

Changes the PivotCache object of the specified PivotTable.

Syntax

expression.ChangePivotCache (bstr)

expression A variable that represents a PivotTable object.

Parameters

Name Required/Optional Data type Description
bstr Required String A PivotTable or PivotCache object that represents the new PivotCache for the specified PivotTable.

Remarks

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.

Example

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)

Support and feedback

Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.