Class SortField (Excel VBA)

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

Member in collection

Item

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.Add, SortFields.Add2 and SortFields.Item.

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

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

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

SetIcon - Sets an icon for a SortField object.

SortFields.Add - Creates a new sort field and returns a SortFields object.

SortFields.Add2 - Creates a new sort field and returns a SortFields object that can optionally sort data types with the SubField defined.

SortFields.Clear - Clears all the SortFields objects.

Properties

SortFields.Item (Default member) - Returns a SortField object that represents a collection of items that can be sorted in a workbook.

CustomOrder specifies a custom order to sort the fields.

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

Key specifies the range that is currently being sorted on.

Order determines the sort order for the values specified in the key.

Priority specifies the priority for the sort field.

SortOn returns or sets the attribute of the cell to sort on.

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.

Range - Represents a cell, a row, a column, a selection of cells containing one or more contiguous blocks of cells, or a 3D range.