Passing Collection to function

N

Nigel RS

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, before:=j
mCol.Add Swap2, before:=i
mCol.Remove i + 1
mCol.Remove j + 1
End If
Next j
Next i
End Function
 
N

Nigel RS

Sorry everyone, I made the mistake...

Call SortCollection(cA)

or

SortCollection cA

Work OK!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top