मैं ओपी निर्दिष्ट कार्यपत्रकों लेकिन इसके लायक टिप्पण एक नया वर्कशीट बनाने कि, एक स्क्रैच पैड के रूप में उपयोग वर्कशीट कार्यों के साथ तरह करने के लिए उपयोग नहीं कर पता है, तो एक से भी कम समय पहलू से सफाई लंबे समय तक हो जाने के बाद 2. लेकिन आपके पास सॉर्ट वर्कशीट फ़ंक्शन के पैरामीटर द्वारा वितरित सभी लचीलापन भी है।
मेरे सिस्टम पर, अंतर नीचे विधि के लिए @ tannman357 और 96 msec द्वारा बहुत अच्छी रिकर्सिव रूटीन के लिए 55 एमसीसी था। वे कई रनों पर औसत समय हैं।
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
स्रोत
2014-08-26 15:41:45
एक ऐरे को सॉर्ट करने पर संपूर्ण ट्यूटोरियल। एलिस ने आपको सरणी को सॉर्ट करने के लिए कई विकल्प दिए हैं :) अपना चयन करें। http://www.vbforums.com/showthread.php?t=473677 –
पोस्ट http://stackoverflow.com/a/11012529/797393 देखें। – Cylian