'Add the following to the module
-------------------------------------------------------------------
Option Explicit
Public Function SortItemCollection(col As Collection, strPropertyName, Optional blnCompareNumeric As Boolean = False) As Collection
Dim colNew As Collection
Dim objCurrent As Object
Dim objCompare As Object
Dim lngCompareIndex As Long
Dim strCurrent As String
Dim strCompare As String
Dim blnGreaterValueFound As Boolean
'make a copy of the collection, ripping through it one item
'at a time, adding to new collection in right order...
Set colNew = New Collection
For Each objCurrent In col
'get value of current item...
strCurrent = CallByName(objCurrent, strPropertyName, VbGet)
'setup for compare loop
blnGreaterValueFound = False
lngCompareIndex = 0
For Each objCompare In colNew
lngCompareIndex = lngCompareIndex + 1
'optimization - instead of doing this for every iteration, have 2 different loops...
If blnCompareNumeric = True Then
'this means we are looking for a numeric sort order...
If Val(strCurrent) < Val(strCompare) Then
'found an item in compare collection that is greater...
'add it to the new collection...
blnGreaterValueFound = True
colNew.Add objCurrent, , lngCompareIndex
Exit For
End If
Else
'this means we are looking for a string sort...
If strCurrent < strCompare Then
'found an item in compare collection that is greater...
'add it to the new collection...
blnGreaterValueFound = True
colNew.Add objCurrent, , lngCompareIndex
Exit For
End If
End If
Next
'if we didn't find something bigger, just add it to the end of the new collection...
If blnGreaterValueFound = False Then
colNew.Add objCurrent
End If
Next
'return the new collection...
Set SortItemCollection = colNew
Set colNew = Nothing