04 Sort - AndrewMB2/Logic-Architect-for-Excel-VBA GitHub Wiki

Sort method

Sorts on one or more keys. Returns True is successful, otherwise false.

Applies to

TableData ArrData RsetData Xdata XShared

Parameters

Name Type Description
Key1 Variant Name or number of the first key field.
Order1 xlSortOrder enumeration (optional) First key sort order - the default is xlAscending.
Key2 Variant (optional) Name or number of the second key field.
Order2 xlSortOrder enumeration (optional) Second key sort order - the default is xlAscending.
Key3 Variant (optional) Name or number of the third key field.
Order3 xlSortOrder enumeration (optional) Third key sort order - the default is xlAscending.
Key4 Variant (optional) Name or number of the fourth key field (ArrData only).
Order4 xlSortOrder enumeration (optional) Fourth key sort order - the default is xlAscending (ArrData only).
Key5 Variant (optional) Name or number of the fifth key field (ArrData only).
Order5 xlSortOrder enumeration (optional) Fifth key sort order - the default is xlAscending (ArrData only).
Key6 Variant (optional) Name or number of the sixth key field (ArrData only).
Order6 xlSortOrder enumeration (optional) Sixth key sort order - the default is xlAscending (ArrData only).

Sort on TableData supports up to three keys. If you have more than three keys, just do two sorts, sorting on the least significant keys first.

Sort on ArrData supports up to six keys. The sort uses the QuickSort algorithm which is not stable (i.e. it does not retain the sequence of records with equal keys). If this is needed, add an extra field, assign a record number to it with the Calc method using the inbuilt RecordNumber function, and use this as the last sort key.

RsetData objects are normally sorted by putting an ORDER BY clause in the SQL.