VBA Dictionary: How to modify a Dictionary


VBA Dictionary Change

Dictionaries are lookup structures. Typically, they are filled with data and, once that is done, they are used to look up data. Normally, the key/items pairs in the dictionaries don't change a lot.

However, changes are possible. In a key/item pair, items can be changed. Keys cannot.

Implicit adding can be useful when changing the dictionary. Imagine you have a dictionary that is used to contain statistics.

Be careful whit implicit adding. The behavior of the code depends on the compare mode.

A key/item pair can be removed.

All key/item pairs can be removed at once.

After RemoveAll, the (reference to the) dictionary still exists in the memory. It is not Nothing. Be careful when using a dictionary as an item in a key/item pair. Have a look at the following two pieces of code. The first one probably does not behave as you would expect.