【VBA】Sorting an array【SORT Function】

You can “Sorting an array“!

Use the following Worksheet function:
 SORT Function

array
array
Result
Result

You can use “SORT Function” only in Office365.

PR

VBA Code

As an example, Sorting an array.

Option Explicit

Sub sample()
    
    Dim arr As Variant
    Dim arrSort As Variant
    Dim item As Variant
    
    'Create array
    arr = Array(50, 2, 34, 100, 60)
    
    'Sorting an Array
    arrSort = WorksheetFunction.Sort(arr, 1, 1, True)
    
    For Each item In arrSort
        'Output to "immediate window"
        Debug.Print item
    Next
    
End Sub

Sorting an Array(Line 13).
※1st argument :target array
※2nd argument:1

※3rd argument:1
※4th argument:True

PR

Result

You was able to “Sorting an array“!

Result
PR

FYI No.1

Also, you can “Remove duplicates from an array“!

For more information, see the following article:

PR

FYI No.2

For more information about following, see the following official online manual:

●SORT Function

タイトルとURLをコピーしました