Class Sort (Excel VBA)

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


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


Sorts the range based on the currently applied sort states.



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


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

ActiveSheet.Sort.MatchCase = True


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


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


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

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


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:=


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


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