Range.Sort (Excel)

Sorts a range of values.

Sort (Key1, Order1, Key2, Type, Order2, Key3, Order3, Header, OrderCustom, MatchCase, Orientation, SortMethod, DataOption1, DataOption2, DataOption3, SubField1)


   Range("C1") = "Index"
   Columns("A:C").Sort key1:=Range("C2"), _
      order1:=xlAscending, header:=xlYes

Arguments

Optional arguments

The following arguments are optional

Key1 (Range) - Specifies the first sort field, either as a range name (String) or Range object; determines the values to be sorted.

Order1 (XlSortOrder) - Determines the sort order for the values specified in Key1.

Possible return values are xlAscending - Sorts the specified field in ascending order. This is the default value, xlDescending - Sorts the specified field in descending order.

Key2 - Second sort field; cannot be used when sorting a PivotTable

Type - Specifies which elements are to be sorted

Order2 (XlSortOrder) - Determines the sort order for the values specified in Key2.

Possible return values are xlAscending - Sorts the specified field in ascending order. This is the default value, xlDescending - Sorts the specified field in descending order.

Key3 - Third sort field; cannot be used when sorting a PivotTable

Order3 (XlSortOrder) - Determines the sort order for the values specified in Key3.

Possible return values are xlAscending - Sorts the specified field in ascending order. This is the default value, xlDescending - Sorts the specified field in descending order.

Header (XlYesNoGuess) - Specifies whether the first row contains header information. xlNo is the default value; specify xlGuess if you want Excel to attempt to determine the header.

Possible return values are xlGuess - Excel determines whether there is a header, and where it is, if there is one, xlNo - Default. The entire range should be sorted, xlYes - The entire range should not be sorted.

OrderCustom - Specifies a one-based integer offset into the list of custom sort orders

MatchCase (Boolean) - Set to True to perform a case-sensitive sort, False to perform a non-case-sensitive sort; cannot be used with PivotTables.

Orientation (XlSortOrientation) - Specifies if the sort should be by row (default) or column. Set xlSortColumns value to 1 to sort by column. Set xlSortRows value to 2 to sort by row (this is the default value).

Possible return values are xlSortColumns - Sorts by column, xlSortRows - Sorts by row. This is the default value.

SortMethod (XlSortMethod) - Specifies the sort method.

Possible return values are xlPinYin - Phonetic Chinese sort order for characters. This is the default value, xlStroke - Sort by the quantity of strokes in each character.

DataOption1 (XlSortDataOption) - Specifies how to sort text in the range specified in Key1; does not apply to PivotTable sorting.

Possible return values are xlSortNormal - default. Sorts numeric and text data separately, xlSortTextAsNumbers - Treat text as numeric data for the sort.

DataOption2 (XlSortDataOption) - Specifies how to sort text in the range specified in Key2; does not apply to PivotTable sorting.

Possible return values are xlSortNormal - default. Sorts numeric and text data separately, xlSortTextAsNumbers - Treat text as numeric data for the sort.

DataOption3 (XlSortDataOption) - Specifies how to sort text in the range specified in Key3; does not apply to PivotTable sorting.

Possible return values are xlSortNormal - default. Sorts numeric and text data separately, xlSortTextAsNumbers - Treat text as numeric data for the sort.

SubField1