Share via


Sort Method

Sorts a range or, if the specified range contains only one cell, the current region

expression.Sort(ColumnKey, Order, Header)

*expression   * An expression that returns a Range object.

ColumnKey    Optional Long. The number of the first sort column. The default value is 1.

XlSortOrder

XlSortOrder can be one of these XlSortOrder constants.
xlAscendingdefault
xlDescending

XlYesNoGuess

XlYesNoGuess can be one of these XlYesNoGuess constants.
xlGuess Have the method determine whether the first row contains headers.
xlNodefault The first row does not contain headers.
xlYes The first row contains headers.

Example

This example sorts the range A1:F10 in descending order based on column B.

Sub SortData() Dim ssConstants Set ssConstants = Spreadsheet1.Constants ' Sort Range A1:F10 on column B in descending order and specify that ' row 1 contains headings. Spreadsheet1.ActiveSheetRange("A1:F10").Sort 2, _ ssConstants.xlDescending, ssConstants.xlYes End Sub

Applies to | Range Object

See Also | AllowSorting Property