Skip to content

Latest commit

 

History

History
48 lines (29 loc) · 1.5 KB

Excel.PivotTable.ChangePivotCache.md

File metadata and controls

48 lines (29 loc) · 1.5 KB
title keywords f1_keywords api_name ms.assetid ms.date ms.localizationpriority
PivotTable.ChangePivotCache method (Excel)
vbaxl10.chm235184
vbaxl10.chm235184
Excel.PivotTable.ChangePivotCache
1b1ee1b4-0ed6-641a-3e1d-739461fa0466
05/08/2019
medium

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)

[!includeSupport and feedback]