79717083

Date: 2025-07-28 09:02:44
Score: 1
Natty:
Report link

In my experience, arrays are much faster only if you know the size of the dataset you are processing. I don't see much of a difference in performance if you are using collections over dictionaries (using the scripting library). To avoid external references, I tend to stick with collections and use an embedded class to hold the data. The class makes the key : value pair updatable (which isn't usually possible with collections). You will need to mimic some dictionary-like functions (i.e. "Exists"), but this is straightforward.

To aid this, I've create a clsDictionary class that does everything, and there are plenty of examples available online. Some even include additional useful functions like "Insert" and "Sort" to keep the the records in key or value order. In a test of 10,000 items, the search speed is roughly a third of that of a standard dictionary. Other functions, like inserting a key : value are marginally faster using a collection, but I don't really notice this difference in the real world.

Another significant advantage of collections is being able to handle complex classes as values. While this is possible with dictionaries, it can get ugly very quickly. On balance it works well for me, but my recordsets are all relatively small. If I need to accommodate larger recordsets, I use ADODB and create a database table.

I strongly recommend Paul Kelly's https://excelmacromastery.com/excel-vba-collections/ as a tutorial.

Reasons:
  • Blacklisted phrase (0.5): I need
  • Long answer (-1):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Simon Wilson