View Single Post
 
Old 04-01-2020, 06:57 AM
BobBridges's Avatar
BobBridges BobBridges is offline Windows 7 64bit Office 2010 32bit
Expert
 
Join Date: May 2013
Location: USA
Posts: 700
BobBridges has a spectacular aura aboutBobBridges has a spectacular aura about
Default How to write a VBA subroutine one of whose arguments specifies WHICH PROPERTY to use in a loop

I'm writing a medium-complex set of Excel reports that requires sorting various collections. In each case I want to sort a collection based on a different property, but the logic is the same aside from that. So it's time to think about a subroutine that'll do the job.

But is it possible? For instance, in one case I want to sort a collection of User objects based on the LFName property; in another I'm sorting a collection of Xct objects on the Name property. I know a third such case is coming up where I want to sort a collection of objects based on a different property yet again.

So I want to write a subroutine that sorts the specified collection on the specified property. I'm not asking about how to do the sort; I'm already doing that. But is it possible for the caller to specify a different property (not a particular value) in each call? I've a notion I've seen something like that, long ago, but at the time I no doubt shrugged and thought it was too exotic for me to expect to need.
Reply With Quote