Add Method (PivotCaches Collection)

See Also         Example         Applies To

Adds a new PivotTable cache to a PivotCaches collection. Returns a PivotCache object.

Syntax

expression.Add(SourceType, SourceData)

expression   An expression that returns a PivotCaches object.

SourceType   Optional XlPivotTableSourceType. The source of the PivotTable cache data. Can be one of the XlPivotTableSourceType constants listed in the following table.

Constant Description
xlConsolidation Multiple consolidation ranges
xlDatabase A Microsoft Excel list or database
xlExternal Data from another application (SourceData must not be specified)
xlPivotTable The same data source as another PivotTable report

SourceData   Optional Variant. The data for the new PivotTable cache. This argument is required if SourceType isn’t xlExternal. Can be a Range object, an array of ranges, or a text constant that represents the name of an existing PivotTable report. For an external database, this is a two-element array. The first element is the connection string specifying the provider of the data. The second element is the SQL query string used to get the data. If you specify this argument, you must also specify SourceType.

Remarks

If the PivotTable cache isn’t referenced by a PivotTable object, the PivotTable cache is automatically deleted before the workbook is saved.