Sorts the columns or rows of the current matrix object.
MatrixObject.SortCols RowIndex, SortOrder, PermIndex MatrixObject.SortRows ColIndex, SortOrder, PermIndex
The following table describes the possible values for the SortOrder parameter.
| Constant | Description | Value |
|---|---|---|
| bmSortAscending | (Default) Sort in ascending order. | 0 |
| bmSortDescending | Sort in descending order. | 1 |
PermIndex can be used as an input for ReorderCols or ReorderRows method.
Error 1319 is returned if RowIndex exceeds matrix size.
Error 1320 is returned if ColIndex exceeds matrix size.
Private Sub MatrixSortReorderRows()
Dim A As Matrix, B As Matrix
Dim PI As Variant
Set A = New Matrix
A.Size 6, 6
A.FillRandom
Set B = New Matrix
B.Size 6, 1
B.FillRandom
Debug.Print "A = "
Debug.Print A.GetString
Debug.Print "B = "
Debug.Print B.GetString
A.SortRows 0, msoAscending, PI
B.ReorderRows PI
Debug.Print "A sorted"
Debug.Print A.GetString
Debug.Print "B reordered"
Debug.Print B.GetString
End Sub
A = | 6.000 2.000 8.000 6.000 5.000 4.000 | | 9.000 8.000 7.000 2.000 9.000 7.000 | | 5.000 3.000 0.000 1.000 4.000 1.000 | | 2.000 10.000 4.000 1.000 0.000 0.000 | | 4.000 5.000 6.000 6.000 6.000 2.000 | | 7.000 5.000 4.000 1.000 6.000 8.000 | B = | 5.000 | | 3.000 | | 9.000 | | 7.000 | | 10.000 | | 9.000 | A sorted | 2.000 10.000 4.000 1.000 0.000 0.000 | | 4.000 5.000 6.000 6.000 6.000 2.000 | | 5.000 3.000 0.000 1.000 4.000 1.000 | | 6.000 2.000 8.000 6.000 5.000 4.000 | | 7.000 5.000 4.000 1.000 6.000 8.000 | | 9.000 8.000 7.000 2.000 9.000 7.000 | B reordered | 7.000 | | 10.000 | | 9.000 | | 5.000 | | 9.000 | | 3.000 |