Znam OP określony nie używając arkuszy ale jego warto zauważyć, że tworzenie nowego arkusza, używając go jako notatniku zrobić sortowania z funkcji arkusza, a następnie sprzątanie po jest dłuższy o mniej niż czynnik z 2. Ale masz także całą elastyczność dostarczoną przez parametry funkcji Sort WorkSheet.
W moim systemie różnica wyniosła 55 ms dla bardzo ładnej procedury rekursywnej przez @ tannman357 i 96 ms dla poniższej metody. Są to średnie czasy w kilku seriach.
Sub rangeSort(ByRef a As Variant)
Const myName As String = "Module1.rangeSort"
Dim db As New cDebugReporter
db.Report caller:=myName
Dim r As Range, va As Variant, ws As Worksheet
quietMode qmON
Set ws = ActiveWorkbook.Sheets.Add
Set r = ws.Cells(1, 1).Resize(UBound(a), 1)
r.Value2 = rangeVariant(a)
r.Sort Key1:=r.Cells(1), Order1:=xlDescending
va = r.Value2
GetColumn va, a, 1
ws.Delete
quietMode qmOFF
End Sub
Function rangeVariant(a As Variant) As Variant
Dim va As Variant, i As Long
ReDim va(LBound(a) To UBound(a), 0)
For i = LBound(a) To UBound(a)
va(i, 0) = a(i)
Next i
rangeVariant = va
End Function
Sub quietMode(state As qmState)
Static currentState As Boolean
With Application
Select Case state
Case qmON
currentState = .ScreenUpdating
If currentState Then .ScreenUpdating = False
.Calculation = xlCalculationManual
.DisplayAlerts = False
Case qmOFF
If currentState Then .ScreenUpdating = True
.Calculation = xlCalculationAutomatic
.DisplayAlerts = True
Case Else
End Select
End With
End Sub
Cały tutorial na temat sortowania tablicy. Ellis dał ci wiele możliwości sortowania tablicy :) Wybierz. http://www.vbforums.com/showthread.php?t=473677 –
Zobacz wpis http://stackoverflow.com/a/11012529/797393. – Cylian