Skip to main content Link Search Menu Expand Document (external link) Copy Copied

SortByField

Sorts the imported CSV/TSV data.


Syntax

expression.SortByField([fromIndex:= -1], [toIndex:= -1], [SortingKey:= 1], [SortAlgorithm:= SortingAlgorithms.SA_Quicksort])

Parameters

Part Description
fromIndex Optional. Identifier specifying a Long Type variable.
toIndex Optional. Identifier specifying a Long Type variable.
SortingKey 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 or ImportFromCSVstring method.

See also
ImportFromCSV method, ImportFromCSVstring method, CSVArrayList class, Sort method.

Behavior

When the fromIndex parameter is omitted, the sorting of the data starts at the first field of the record specified in the SortingKey parameter. Omitting the toIndex parameter takes the sorting to the last available field. If the SortingKey parameter is omitted, the data will be sorted on the first field in ascending order, set this parameter to a negative Integer to sort the data in descending order on the given record (e.g. SortingKey:=-2 will sort in descending order on the second record). In addition, the user can pass a one-dimensional array in the SortingKey parameter to achieve multilevel data sorting on several fields at once.

☕Example

Sub SortByField()
    Dim CSVint As CSVinterface
    
    Set CSVint = New CSVinterface
    With CSVint.parseConfig
        .path = Environ("USERPROFILE") & "\Desktop\Demo_100000records.csv"
    End With
    With CSVint
        .ImportFromCSV .parseConfig
        .SortByField SortingKey:=1, SortAlgorithm:=SA_Quicksort                 'Sort the data in ascending order on header record.
                                                                                'The operation will change fields order instead
                                                                                'of records ordering.
    End With
    Set CSVint = Nothing
End Sub

Back to Methods overview