expression.Sort(ColumnKey, Order, Header)
expression An expression that returns a Range object.
ColumnKey Optional Long. The number of the first sort column. The default value is 1.
Order Optional XlSortOrder . The sort order.
XlSortOrder can be one of these XlSortOrder constants. |
xlAscending default |
xlDescending |
Header Optional XlYesNoGuess . Determines whether the first row contains headers.
XlYesNoGuess can be one of these XlYesNoGuess constants. |
xlGuess Have the method determine whether the first row contains headers. |
xlNo default The first row does not contain headers. |
xlYes The first row contains headers. |
Example
This example sorts the range A1:F10 in descending order based on column B.
Sub SortData()
Dim ssConstants
Set ssConstants = Spreadsheet1.Constants
' Sort Range A1:F10 on column B in descending order and specify that
' row 1 contains headings.
Spreadsheet1.ActiveSheetRange("A1:F10").Sort 2, _
ssConstants.xlDescending, ssConstants.xlYes
End Sub