Hi,
Make it a function
Code:
Function BubbleSort(arr As Variant, Optional numEls As Variant, _
Optional descending As Boolean)
Dim value As Variant
Dim index As Long
Dim firstItem As Long
Dim indexLimit As Long, lastSwap As Long
' account for optional arguments
If IsMissing(numEls) Then numEls = UBound(arr)
firstItem = LBound(arr)
lastSwap = numEls
Do
indexLimit = lastSwap - 1
lastSwap = 0
For index = firstItem To indexLimit
value = arr(index)
If (value > arr(index + 1)) Xor descending Then
' if the items are not in order, swap them
arr(index) = arr(index + 1)
arr(index + 1) = value
lastSwap = index
End If
Next
Loop While lastSwap
BubbleSort = arr
End Function
and call like
Code:
Sub test()
Dim a, b
a = [a10:a23]
b = BubbleSort(Application.Transpose(a))
[b10:b23] = Application.Transpose(b)
End Sub
HTH
Bookmarks