AutoSort Method

Applies To

PivotField object.

Description

Establishes automatic PivotTable field-sorting rules.

Syntax

expression.AutoSort(Order, Field)

expression Required. An expression that returns a PivotField object.

Order Required Long. The sort order. Can be either of the following XlSortOrder constants: xlAscending or xlDescending. Can also be xlManual to disable automatic sorting.

Field Required String. The name of the sort key field.

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"