AutoSort Method

Microsoft Excel Visual Basic

Establishes automatic field-sorting rules for PivotTable reports.

expression.AutoSort(Order, Field)

expression    Required. An expression that returns one of the objects in the Applies To list.

Order   Required XlSortOrder. The sort order.

XlSortOrder can be one of these XlSortOrder constants.
xlAscending
xlDescending
xlManual. To disable automatic sorting.

Field    Required String. The name of the sort key field. You must specify the unique name (as returned from the SourceName property), and not the displayed name.

Example

This example sorts the Company field in descending order, based on the sum of sales.

ActiveSheet.PivotTables(1).PivotField("Company") _
    .AutoSort xlDescending, "Sum of Sales"