I have a variant array of string values [i.e. Dim Unsorted As Variant] and I
want to sort them.
Does anyone have a routine that will accomplish this task?
TIA
I have a variant array of string values [i.e. Dim Unsorted As Variant] and I
want to sort them.
Does anyone have a routine that will accomplish this task?
TIA
'*********
' Bubble Sort an array of any type
' Author: The VB2TheMax Team
Sub BubbleSort(arr As Variant, Optional descending As Boolean, _
Optional numEls As Variant)
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
End Sub
'**********
"VBA" <nospam@nowhere.com> wrote in message news:41b83d5d$1_1@newsprd01...
I have a variant array of string values [i.e. Dim Unsorted As Variant] and
I
want to sort them.
Does anyone have a routine that will accomplish this task?
TIA
http://www.nist.gov/dads/
Search for sort and you will see a ton of sort algorithms.
- Jorge
"VBA" <nospam@nowhere.com> wrote in message news:41b83d5d$1_1@newsprd01...
I have a variant array of string values [i.e. Dim Unsorted As Variant] and
I
want to sort them.
Does anyone have a routine that will accomplish this task?
TIA
Problem With Variant