Check for VBA Key Nested Dictionary

I am trying to use a dictionary of dictionaries in Excel VBA. I am trying to find out if there is already a key in the enclosed dictionary, and if not, add it.

My data is as follows:

Country, Customer, Purchased US, Alan, Lawnmower US, Alan, Hammer US, Karen, Donkey US, Simon, Mustang MX, Carl, Lawnmower MX, Alan, Donkey ... 

The data structure that I mean looks like dictionary --> dictionary --> array - i.e. country --> customer --> purchased .

The code I use to find out if a country exists in the country dictionary:

 If Not dataset.Exists(country) Then ... 

However, code that looks like this does not work:

 If Not dataset.Exists(country)(customer) Then .... 

How do you check the next level of entries in a dictionary? Is this a case of storing the contents of a country dictionary in an array, and then checking for (what seems like a mess)?

+6
source share
1 answer

You can use this:

 If Not dataset.Exists(country) Then 'if country doesn't exists do sth ElseIf Not dataset(country).Exists(customer) Then 'if country exists, but customer doesn't exists do sth End If 
+4
source

All Articles