Syntax Laurent Longre's Morefunc VSORT with arrays?
Simply because there are often too many rows for the sheet.
RBS
"Michel Pierron" wrote in message
...
Hi RB,
Why not use the sorting properties of Excel ?
Sub Tri2DArray()
Application.ScreenUpdating = False
Dim arr As Variant, Tps As Single
Dim i As Long, c As Long
Randomize
ReDim arr(1 To 10000, 1 To 4)
For i = 1 To 10000
arr(i, 1) = Int((i * Rnd) + 1)
'Cells(i, 1) = arr(i, 1)
If i 1000 Then
For c = 2 To 4
arr(i, c) = Int((i * Rnd) + 1)
'Cells(i, c) = arr(i, c)
Next c
End If
Next
Tps = Timer
Worksheets.Add
Set Rng = Range("A1:D" & UBound(arr))
Rng.value = arr
Rng.Sort Key1:=Range("A1"), Order1:=1, Key2:=Range("B1") _
, Order2:=1, Key3:=Range("C1"), Order3:=1, Header:=0 _
, OrderCustom:=1, MatchCase:=False, Orientation:=1
arr = Rng.value
Application.DisplayAlerts = False
ActiveSheet.Delete
Application.DisplayAlerts = True
MsgBox Timer - Tps
Set Rng = Nothing
'For i = 1 To UBound(arr)
'Cells(i, 6) = arr(i, 1)
'Cells(i, 7) = arr(i, 2)
'Cells(i, 8) = arr(i, 3)
'Cells(i, 9) = arr(i, 4)
'Next i
End Sub
MP
"RB Smissaert" a écrit dans le message de
...
To make matters it a bit clearer I thought it would be better to start a
new
thread about this.
Previous thread was: Fastest way to sort large 2-D arrays?
I am trying to figure out how to use Laurent Longre's VSORT in the .xll
add-in MoreFunc.
The help file makes it clear for ranges, but not for VBA arrays.
Say I have a 10 column array that I want sorted ascending on column 2 and
descending on column 5
what would the syntax be for that?
The only thing that I have got working sofar is this:
Sub Test()
Dim arr(1 To 10000, 1 To 5) As Long
Dim arr2
Dim i As Long
Dim c As Long
For i = 1 To 10000
arr(i, 1) = Int((i * Rnd) + 1)
For c = 2 To 5
arr(i, c) = i
Next
Next
arr2 = Application.Run([VSORT], arr, arr, 0) 'this works
End Sub
This will sort descending on column 1.
Thanks for any advice.
RBS
|