I have found the VBA code below after a Google search. It sorts an array alphabetically and is faster than Bubblesort. However I can't figure out how to modify the code to sort my single dimensional array, which is a file list, on the file extension? It's a mixture of Word files (.doc) and Excel files (.xlsx) in the array. I would like to sort the files so all the Word files are sorted before the Excel files. To clarify the array after the sort would be as per the following example...
(filename.doc)
(filename.doc)
(filename.doc)
(filename.doc)
(filename.doc)
(filename.xlsx)
(filename.xlsx)
(filename.xlsx)
(filename.xlsx)
The code...
Sub Quicksort(vArray As Variant, arrLbound As Long, arrUbound As Long)
'Sorts a one-dimensional VBA array from smallest to largest
'using a very fast quicksort algorithm variant.
Dim pivotVal As Variant
Dim vSwap As Variant
Dim tmpLow As Long
Dim tmpHi As Long
tmpLow = arrLbound
tmpHi = arrUbound
pivotVal = vArray((arrLbound + arrUbound) \ 2)
While (tmpLow <= tmpHi) 'divide
While (vArray(tmpLow) < pivotVal And tmpLow < arrUbound)
tmpLow = tmpLow + 1
Wend
While (pivotVal < vArray(tmpHi) And tmpHi > arrLbound)
tmpHi = tmpHi - 1
Wend
If (tmpLow <= tmpHi) Then
vSwap = vArray(tmpLow)
vArray(tmpLow) = vArray(tmpHi)
vArray(tmpHi) = vSwap
tmpLow = tmpLow + 1
tmpHi = tmpHi - 1
End If
Wend
If (arrLbound < tmpHi) Then Quicksort vArray, arrLbound, tmpHi 'conquer
If (tmpLow < arrUbound) Then Quicksort vArray, tmpLow, arrUbound 'conquer
End Sub
Any help would be greatly appreciated.