| Start | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Properties and Methods A Scripting Dictionary object (opens new window) stores information in Key/Item pairs. The Keys must be unique and not an array but the associated Items can be repeated (their uniqueness is held by the companion Key) and can be of any type of variant or object. A dictionary can be thought of as a two field in-memory database with a primary unique index on the first 'field' (the Key). This unique index on the Keys property allows very fast 'lookups' to retrieve a Key's associated Item value. Properties
Methods
Sample Code |
||||||||||||||||||||||||||||||||||
| Getting unique values with Scripting.Dictionary The which you could then call like this: and Note: This function can be used with any enumerable object. |
||||||||||||||||||||||||||||||||||
| Aggregating data with Scripting.Dictionary (Maximum, Count) Dictionaries are great for managing information where multiple entries occur, but you are only concerned with a single value for each set of entries — the first or last value, the mininmum or maximum value, an average, a sum etc. Consider a workbook that holds a log of user activity, with a script that inserts the username and edit date every time someone edits the workbook:
Let's say you want to output the last edit time for each user, into a worksheet named Notes: and the output will look like this:
If on the other hand you want to output how many times each user edited the workbook, the body of the and the output will look like this:
RemarksYou must add Microsoft Scripting Runtime to the VBA project through the VBE's Tools → References command in order to implement early binding of the Scripting Dictionary object. This library reference is carried with the project; it does not have to be re-referenced when the VBA project is distributed and run on another computer. |
Read Article
https://develop.horje.com/learn/1434/reference