Class SortField (Excel VBA)

The SortField object contains all the sort information for the Worksheet, ListObject, and AutoFilter objects.

The main procedures of class SortField are Delete, SortFields.Add and SortFields.Add2

Set

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

Dim srtfld as SortField
Set srtfld = ActiveSheet.Sort.SortFields(Index:=1)

The following procedures can be used to set variables of type SortField: SortFields.Item, SortFields.Add, SortFields.Add2 and Sort.SortFields

For Each

Here is an example of processing the SortField items in a collection.

Dim srtfld As SortField
For Each srtfld In ActiveSheet.Sort.SortFields
	
Next srtfld

Themes

Some procedures in this class have been grouped together in themes and are described on separate theme pages

Sort/Order with its procedures CustomOrder, Order and SortOn
Add with its procedures SortFields.Add and SortFields.Add2

Methods

These are the main methods of the SortField class

Delete - Removes the specified SortField object from the SortFields collection.

ActiveSheet.Sort.SortFields(1).Delete

Other Methods

ModifyKey - Modify the key value by which values are sorted in the field.

SetIcon - Sets an icon for a SortField object.

SortFields.Clear - Clears all the SortFields objects.

Properties

DataOption specifies how to sort text in the range specified in a SortField object.

Key specifies the range that is currently being sorted on.

Parent returns the parent object for the specified object. Read-only.

Priority specifies the priority for the sort field.

SortOnValue returns the value on which the sort is performed for the specified SortField object.

SubField

SortFields.Count returns the number of objects in the collection.

SortFields.Item returns a SortField object that represents a collection of items that can be sorted in a workbook.

SortFields.Parent returns the parent object for the specified object. Read-only.