SortSpecial Method
Applies To
Range object.
Description
Syntax 1: Uses Far East sorting methods to sort the range, or uses the current region if the range contains only one cell.
Syntax 2: Uses Far East sorting methods to sort a PivotTable. For more information, see the argument list.
Syntax 1
expression.SortSpecial(SortMethod, Key1, Order1, Key2, Type, Order2, Key3, Order3, Header,
úOrderCustom, MatchCase, Orientation)
Syntax 2
expression.SortSpecial(SortMethod, Key1, Order1, Type, OrderCustom, Orientation)
expression Required. An expression that returns a Range object.
SortMethod Optional Variant. Specifies how to sort. Can be one of the following XlSortMethod constants: xlSyllabary (to sort phonetically) or xlCodePage (to sort by code page). The default value is xlSyllabary.
Key1 Optional Variant. The first sort field, as either text (a pivot field or range name) or a Range object ("Dept" or Cells(1, 1), for example).
Order1 Optional Variant. Can be one of the following XlSortOrder constants: xlAscending or xlDescending. Use xlAscending to sort Key1 in ascending order. Use xlDescending to sort Key1 in descending order. The default value is xlAscending.
Key2 Optional Variant. The second sort field, as either text (a pivot field or range name) or a Range object. If this argument is omitted, there's no second sort field. Not used when sorting PivotTables.
Type Optional Variant. Specifies which elements are sorted. Can be one of the following XlSortType constants: xlSortValues or xlSortLabels. Used only when sorting PivotTables.
Order2 Optional Variant. Can be one of the following XlSortOrder constants: xlAscending or xlDescending. Use xlAscending to sort Key2 in ascending order. Use xlDescending to sort Key2 in descending order. The default value is xlAscending. Not used when sorting PivotTables.
Key3 Optional Variant. The third sort field, as either text (a range name) or a Range object. If this argument is omitted, there's no third sort field. Not used when sorting PivotTables.
Order3 Optional Variant. Can be one of the following XlSortOrder constants: xlAscending or xlDescending. Use xlAscending to sort Key3 in ascending order. Use xlDescending to sort Key3 in descending order. The default value is xlAscending. Not used when sorting PivotTables.
Header Optional Variant. Specifies whether the first row contains headers. Can be one of the following XlYesNoGuess constants: xlYes, xlNo, or xlGuess. Use xlYes if the first row contains headers (it shouldn't be sorted). Use xlNo if there are no headers (the entire range should be sorted). Use xlGuess to let Microsoft Excel determine whether there's a header, and to determine where it is, if there is one. The default value is xlNo. Not used when sorting PivotTables.
OrderCustom Optional Variant. 1-based integer offset into the list of custom sort orders. If this argument is omitted, 1 (Normal) is used.
MatchCase Optional Variant. True to do a case-sensitive sort; False to do a sort that's not case sensitive. Not used when sorting PivotTables.
Orientation Optional Variant. If xlTopToBottom or omitted, the sort is done from top to bottom (by row). If xlLeftToRight, the sort is done from left to right (by column).
See Also
Sort method.
Example
This example sorts the range A1:G37 on Sheet1, using cell A1 as the first sort key and cell C1 as the second sort 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