SortSpecial Method

Applies To

Range Object.

Description

Syntax 1: Uses Far-East sorting methods to sort the range, or the current region if the range contains only one cell.

Syntax 2: Uses Far-East sorting methods to sort a PivotTable; see the argument list for more information.

Syntax 1

object.SortSpecial(sortMethod, key1, order1, key2, type, order2, key3, order3, header, orderCustom, matchCase, orientation)

Syntax 2

object.SortSpecial(sortMethod, key1, order1, type, orderCustom, orientation)

object

Required. The Range object.

sortMethod

Optional. Specifies how to sort (xlSyllabary to sort phonetically or xlCodePage to sort by code page). The default value is xlSyllabary.

key1

Optional. The first sort field, as text (a pivot field or range name) or a Range object ("Dept" or Cells(1, 1), for example).

order1

Optional. If xlAscending or omitted, key1 is sorted in ascending order. If xlDescending, key1 is sorted in descending order.

key2

Optional. The second sort field, as text (a pivot field or range name) or a Range object. If omitted, there is no second sort field. Not used when sorting PivotTables.

type

Optional. Only used when sorting PivotTables. Specifies which elements are sorted, either xlSortValues or xlSortLabels.

order2

Optional. Sort order for key2 (xlAscending or xlDescending); if omitted, xlAscending is assumed. Not used when sorting PivotTables.

key3

Optional. The third sort field, as text (a range name) or a Range object. If omitted, there is no third sort field. Not used when sorting PivotTables.

order3

Optional. Sort order for key3 (xlAscending or xlDescending); if omitted, xlAscending is assumed. Not used when sorting PivotTables.

header

Optional. If xlYes, the first row contains headers (it is not sorted). If xlNo or omitted, no headers exist (the entire range is sorted). If xlGuess, Microsoft Excel guesses if there is a header, and where it is if there is one. Not used when sorting PivotTables.

orderCustom

Optional. One-based integer offset into the list of custom sort orders. If omitted, one (Normal) is used.

matchCase

Optional. If True, the sort is case sensitive. If False, the sort is not case sensitive. Not used when sorting PivotTables.

orientation

Optional. If xlTopToBottom or omitted, the sort is done from top to bottom (sort rows). If xlLeftToRight, the sort is done from left to right (sort columns).

Example

This example sorts the range A1:G37 on Sheet1, using cell A1 as the first sort key and cell C1 as the second key. The sort is done in ascending code page order by row, and there are no headers.


Worksheets("Sheet1").Range("A1:G37").SortSpecial _
    sortMethod:=xlCodePage, _
    key1:=Range("A1"), order1:=xlAscending, _
    key2:=Range("C1"), order2:=xlAscending