Worksheet.PivotTableWizard (Excel)

Creates a new PivotTable report. This method doesn't display the PivotTable Wizard. This method isn't available for OLE DB data sources. Use the Add method to add a PivotTable cache, and then create a PivotTable report based on the cache.

PivotTableWizard (SourceType, SourceData, TableDestination, TableName, RowGrand, ColumnGrand, SaveData, HasAutoFormat, AutoPage, Reserved, BackgroundQuery, OptimizeCache, PageFieldOrder, PageFieldWrapCount, ReadData, Connection)


Dim pvtPivotTableWizard As PivotTable
Set pvtPivotTableWizard = ActiveSheet.PivotTableWizard(xlDatabase, Range("A1:C100"))

Arguments

Optional arguments

The following arguments are optional

SourceType (XlPivotTableSourceType) - An XlPivotTableSourceType value that represents the source of the report data. If you specify this argument, you must also specify SourceData. If SourceType and SourceData are omitted, Microsoft Excel assumes that the source type is xlDatabase, and the source data comes from the named range Database. If this named range doesn't exist, Excel uses the current region if the current selection is in a range of more than 10 cells that contain data. If this isn't true, this method will fail.


Possible values are

xlConsolidation Multiple consolidation ranges.
xlDatabase Microsoft Excel list or database.
xlExternal Data from another application.
xlPivotTable Same source as another PivotTable report.
xlScenario Data is based on scenarios created using the Scenario Manager.

SourceData (Range) - The data for the new report. Can be a Range object, an array of ranges, or a text constant that represents the name of another report. For an external database, SourceData is an array of strings containing the SQL query string, where each element is up to 255 characters in length. You should use the Connection argument to specify the ODBC connection string. For compatibility with earlier versions of Excel, SourceData can be a two-element array. The first element is the connection string specifying the ODBC source for the data. The second element is the SQL query string used to get the data. If you specify SourceData, you must also specify SourceType. If the active cell is inside the SourceData range, you must specify TableDestination as well.

TableDestination (Range) - A Range object specifying where the report should be placed on the worksheet. If this argument is omitted, the report is placed at the active cell.

TableName (String) - A string that specifies the name of the new report.

RowGrand (Boolean) - True to show grand totals for rows in the report.

ColumnGrand (Boolean) - True to show grand totals for columns in the report.

SaveData (Boolean) - True to save data with the report. False to save only the report definition.

HasAutoFormat (Boolean) - True to have Excel automatically format the report when it's refreshed or when fields are moved.

AutoPage (XlPivotTableSourceType) - Valid only if SourceType is xlConsolidation. True to have Excel create a page field for the consolidation. If AutoPage is False, you must create the page field or fields.


Possible values are

xlConsolidation Multiple consolidation ranges.
xlDatabase Microsoft Excel list or database.
xlExternal Data from another application.
xlPivotTable Same source as another PivotTable report.
xlScenario Data is based on scenarios created using the Scenario Manager.

Reserved - Not used by Excel

BackgroundQuery (Boolean) - True to have Excel perform queries for the report asynchronously (in the background). The default value is False.

OptimizeCache (Boolean) - True to optimize the PivotTable cache when it's constructed. The default value is False.

PageFieldOrder (XlOrder) - The order in which page fields are added to the PivotTable report's layout. Can be one of the following XlOrder constants: xlDownThenOver (default) or xlOverThenDown.

Possible return values are xlDownThenOver - Process down the rows before processing across pages or page fields to the right, xlOverThenDown - Process across pages or page fields to the right before moving down the rows.

PageFieldWrapCount (Long) - The number of page fields in each column or row in the PivotTable report. The default value is 0 (zero).

ReadData (Boolean) - True to create a PivotTable cache that contains all records from the external database; this cache can be very large. If ReadData is False, you can set some of the fields as server-based page fields before the data is actually read.

Connection (PivotCache) - A string that contains ODBC settings that allow Excel to connect to an ODBC data source. The connection string has the form ODBC;. This argument overrides any previous setting for the PivotCache object's Connection property.