Class Sort (Excel VBA)

The class Sort represents a sort of a range of data.

Set

To use a Sort class variable it first needs to be instantiated, for example

Dim srt as Sort
Set srt = ActiveSheet.Sort

The following procedures can be used to set variables of type Sort: AutoFilter.Sort, ListObject.Sort, QueryTable.Sort and Worksheet.Sort

Apply

Sorts the range based on the currently applied sort states.

ActiveSheet.Sort.Apply

Header

Specifies whether the first row contains header information.

Possible 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.

xlNo is the default value. You can specify xlGuess if you want Excel to attempt to determine the header.

ActiveSheet.Sort.Header = xlGuess

MatchCase

Set to True to perform a case-sensitive sort, or set to False to perform a non-case-sensitive sort.

ActiveSheet.Sort.MatchCase = True

Orientation

Specifies the orientation for the sort.

Possible Values are xlSortColumns - Sorts by column, xlSortRows - Sorts by row. This is the default value.
ActiveSheet.Sort.Orientation = xlSortColumns

Parent

Returns the parent object for the specified object. Read-only.

Rng

Return the range of values on which the sort is performed.

Dim rngRng As Range
Set rngRng = ActiveSheet.Sort.Rng

SetRange

Sets the range over which the sort occurs.

SetRange (Rng)

Rng: Specifies the range over which the sort represented by the Sort object occurs.

ActiveSheet.Sort.SetRange Rng:=

SortFields

Returns the SortFields object that represents the collection of sort fields associated with the Sort object.

Dim sfsSortFields As SortFields
Set sfsSortFields = ActiveSheet.Sort.SortFields

SortMethod

Specifies the sort method for Chinese languages.

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