Sort
Sorts the imported CSV/TSV data.
Syntax
expression.Sort
([fromIndex:= -1], [toIndex:= -1], [SortingKeys:= 1], [SortAlgorithm:= SortingAlgorithms.SA_Quicksort])
Parameters
Part | Description |
---|---|
fromIndex | Optional. Identifier specifying a Long Type variable. |
toIndex | Optional. Identifier specifying a Long Type variable. |
SortingKeys | Optional. Identifier specifying a Variant Type variable. |
SortAlgorithm | Optional. Identifier specifying a member of the SortingAlgorithms Enumeration. |
Returns value
Type: CSVinterface
📝Note
Before sort data, is required to make a call to the
ImportFromCSV
orImportFromCSVstring
method.
Behavior
When the fromIndex parameter is omitted the data sorting start on the second record when the ParseConfig.headers
is set to True
and ParseConfig.headersOmission
is set to False
. Omitting the toIndex parameter takes the sorting to the last available record. If the SortingKeys parameter is omitted the data will be sorted on the first column/field in ascending order, set this parameter to a negative Integer
to sort the data in descending order on the given column (e.g. SortingKeys:=-2
will sort in descending order on the second field). In addition, the user can pass a one-dimensional array in the SortingKeys parameter to achieve multilevel data sorting on several fields at once.
☕Example
Sub Sort()
Dim CSVint As CSVinterface
Dim SortKeys() As Long
Set CSVint = New CSVinterface
With CSVint.parseConfig
.path = Environ("USERPROFILE") & "\Desktop\Demo_100000records.csv"
End With
ReDim SortKeys(0 To 2)
SortKeys(0) = -1: SortKeys(1) = 5: SortKeys(2) = -11
With CSVint
.ImportFromCSV .parseConfig
.Sort SortingKeys:=SortKeys, SortAlgorithm:=SA_Quicksort 'Sort the data in descending order on column 1,
'then sort in ascending order on column 5 and
'sort in descending order on column 11. This
'multi-level sorting is "stable".
.DumpToSheet
End With
Set CSVint = Nothing
End Sub