Name

range.Sort([Key1]), [Order1], [Key2], [Type], [Order2], [Key3], [Order3], [Header], [OrderCustom], [MatchCase], [Orientation], [SortMethod], [DataOption1], [DataOption2], [DataOption3])

Synopsis

Sorts the current active region or a specific range of cells using the specified range, which must be a single cell.

Argument

Settings

Key1

The first row or column to sort. Can be either a single cell range or heading text.

Order1

xlAscending (default) sorts in ascending order; xlDescending sorts in descending order.

Key2

The second row or column to sort.

Type

Specifies which elements should be sorted if you are sorting a PivotTable report.

Order2

Same as Order1.

Key3

The third row or column to sort.

Order3

Same as Order1.

Header

Specifies whether the first row or column contains header information. xlNo (default) sorts the entire row or column; xlYes does not include the first row or column in the sort; xlGuess lets Excel determine if there is a header.

OrderCustom

The index of a custom sort order from the Sort Options dialog box.

MatchCase

True to perform a case-sensitive search.

Orientation

xlSortRows sorts by row; xlSortColumns sorts by column.

SortMethod

For non-English sorts, xlStroke sorts by the quantity of strokes in each character; xlPinYin (default) uses phonetic Chinese sort order.

DataOption1

xlSortTextAsNumber treats text as numeric data for the sort for Key1.

DataOption2

xlSortTextAsNumber treats text as numeric ...

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.