View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Nigel RS[_2_] Nigel RS[_2_] is offline
external usenet poster
 
Posts: 80
Default Passing Collection to function

I have a set of new collections used to store lists of data. I now wish to
sort these collections in order and have a developed a general purpose
function to do just that. However I wish to pass the name of the collection
to my sort routine and I get an error "Argument not optional" as if the name
of the collection is not recognised as a collection.

Basic code structure as follows

' main code
Dim cA as new collection
Dim cB as new collection

' code that fills collection removed (that works ok)

Call SortCollection(cA) '<--- this line fails, although cA is a collection
and contains data

End main code


' SORT FUNCTION
Function SortCollection(mCol As Collection)
' sort the collection into order
Dim i As Long, j As Long
For i = 1 To mCol.Count - 1
For j = i + 1 To mCol.Count
If mCol(i) mCol(j) Then
Swap1 = mCol(i)
Swap2 = mCol(j)
mCol.Add Swap1, befo=j
mCol.Add Swap2, befo=i
mCol.Remove i + 1
mCol.Remove j + 1
End If
Next j
Next i
End Function