Share via


Range.Sort Method

Excel Developer Reference

Sorts a range of values.

Syntax

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

expression   A variable that represents a Range object.

Parameters

Name Required/Optional Data Type Description
Key1 Optional Variant Specifies the first sort field, either as a range name (String) or Range object; determines the values to be sorted.
Order1 Optional XlSortOrder Determines the sort order for the values specified in Key1.
Key2 Optional Variant Second sort field; cannot be used when sorting a pivot table.
Type Optional Variant Specified which elements are to be sorted.
Order2 Optional XlSortOrder Determines the sort order for the values specified in Key2.
Key3 Optional Variant Third sort field; cannot be used when sorting a pivot table.
Order3 Optional XlSortOrder Determines the sort order for the values specified in Key3.
Header Optional 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.
OrderCustom Optional Variant Specifies a one-based integer offset into the list of custom sort orders.
MatchCase Optional Variant Set to True to perform a case-sensitive sort, False to perform non-case sensitive sort; cannot be used with pivot tables.
Orientation Optional XlSortOrientation Specifies if the sort should be in acending or decending order.
SortMethod Optional XlSortMethod Specifies the sort method.
DataOption1 Optional XlSortDataOption Specifies how to sort text in the range specified in Key1; does not apply to pivot table sorting.
DataOption2 Optional XlSortDataOption Specifies how to sort text in the range specified in Key2; does not apply to pivot table sorting.
DataOption3 Optional XlSortDataOption Specifies how to sort text in the range specified in Key3; does not apply to pivot table sorting.

Return Value
Variant

Reference
Example of Using Range.SortSorting Multiple Columns in a Range

See Also