Search notes:

Excel function: large

Sort numbers

The following VBA example fills 10 random numbers (rnd()) into the first column and uses the large(range, n) function to sort these random numbers in the second column:
option explicit

sub main() ' {
 '
 '  Clear active sheet's data:
 '
    activeSheet.usedRange.clearContents

    randomize(700828)
    dim r as long
    for r = 1 to 10
        cells(r, 1)             =   cLng(rnd(-r) * 900 + 100)
        cells(r, 2).formulaR1C1 = "=large(r1c1:r10c1, " &  r &")"
    next r

end sub ' }
Github repository about-Excel, path: /functions/large/sort-numbers.bas
If run, the function produces:
The same can also be achieved with array formulas by combining large and row.

See also

Excel functions

Index