Skip to content

Latest commit

 

History

History
66 lines (42 loc) · 2.22 KB

Excel.PivotTables.md

File metadata and controls

66 lines (42 loc) · 2.22 KB
title keywords f1_keywords api_name ms.assetid ms.date ms.localizationpriority
PivotTables object (Excel)
vbaxl10.chm237072
vbaxl10.chm237072
Excel.PivotTables
5beb33ac-a0fb-3f78-8fdc-d05719512214
03/30/2019
medium

PivotTables object (Excel)

A collection of all the PivotTable objects in the specified workbook.

Remarks

Note

The PivotTables property of the Workbook object does not return all the PivotTable objects in the workbook; instead, it returns only those associated with decoupled PivotCharts. However, the PivotTables method of the Worksheet object returns all the PivotTable objects on the worksheet, irrespective of whether they are associated with decoupled PivotCharts.

Because PivotTable report programming can be complex, it's generally easiest to record PivotTable report actions and then revise the recorded code.

Example

Use the PivotTables method to return the PivotTables collection. The following example displays the number of PivotTable reports on Sheet3.

MsgBox Worksheets("sheet3").PivotTables.Count

Use the PivotTableWizard method to create a new PivotTable report and add it to the collection. The following example creates a new PivotTable report from a Microsoft Excel database (contained in the range A1:C100).

ActiveSheet.PivotTableWizard xlDatabase, Range("A1:C100")

Use PivotTables (index), where index is the PivotTable index number or name, to return a single PivotTable object. The following example makes the Year field a row field in the first PivotTable report on Sheet3.

Worksheets("sheet3").PivotTables(1) _ 
 .PivotFields("year").Orientation = xlRowField

Methods

Properties

See also

[!includeSupport and feedback]