Public Sub QuickSort(SortList As Variant, ByVal First As Integer, ByVal Last As Integer) Dim Low As Integer, High As Integer 'Use Integer for lists up to 32,767 entries. Dim Temp As Variant, TestElement As Variant 'Variant can handle any type of list. Low = First High = Last TestElement = SortList((First + Last) / 2) 'Select an element from the middle. Do Do While SortList(Low) < TestElement 'Find lowest element that is >= TestElement. Low = Low + 1 Loop Do While SortList(High) > TestElement 'Find highest element that is <= TestElement. High = High - 1 Loop If (Low <= High) Then 'If not done, Temp = SortList(Low) ' Swap the elements. SortList(Low) = SortList(High) SortList(High) = Temp Low = Low + 1 High = High - 1 End If Loop While (Low <= High) If (First < High) Then QuickSort SortList, First, High If (Low < Last) Then QuickSort SortList, Low, Last End Sub ' ' here is a little sub to test QSORT on an integer vector ' and to show how it is used: ' Public Sub qsort_integer() Dim thelist(10) As Integer Dim ix As Integer ' ' create a trivial integer array ' For ix = 0 To 9 thelist(ix) = (ix + 5) Mod 9 Next ix Debug.Print "-----------" For ix = 0 To 9 Debug.Print thelist(ix) Next ix Call QuickSort(thelist, 0, 9) Debug.Print "" For ix = 0 To 9 Debug.Print thelist(ix) Next ix End Sub