BobBridges
Active Member
Not sure VBA can do this, but it would be handy if it's possible. I'm writing a set of programs in Excel, and there are some situations where I want to sort a collection. Normally I could sort the data after I load them into a worksheet, but for various reasons that won't work here. We can talk about that in more detail if you care, but meanwhile:
Sorting a collection isn't hard. But so far in each case I want to sort each collection by the value of a single property. So rather than having three different routines to sort collections of three different objects, is it possible to write a single function that'll do the job? Like this:
The three calls would go something like this:
Is this even possible?
Sorting a collection isn't hard. But so far in each case I want to sort each collection by the value of a single property. So rather than having three different routines to sort collections of three different objects, is it possible to write a single function that'll do the job? Like this:
Code:
' Sort the Coll collection by its key property.
Function SortCollection(Coll, KeyProperty)
Set NewColl As Collection
' ...Here I sort the items of Coll into NewColl
Set SortCollection = NewColl
End Function
The three calls would go something like this:
Code:
Set Schools = SortCollection(Schools, District)
'...where Schools is a collection of School objects, and District is a property of the School class
Set Users = SortCollection(Users, UserID) 'where UserID is a property of the objects in the Users collecton
Set Transactions = SortCollection(Transactions, Name) 'where Name is a property of the Transaction class
Is this even possible?
Last edited by a moderator: