检查VBA中是否存在嵌套字典键
我正在尝试使用Excel VBA中的词典字典。 我试图找出是嵌套字典是否已经有一个关键,如果没有,添加它。
我的数据如下所示:
Country, Customer, Purchased US, Alan, Lawnmower US, Alan, Hammer US, Karen, Donkey US, Simon, Mustang MX, Carl, Lawnmower MX, Alan, Donkey ...
我想到的数据结构看起来像dictionary --> dictionary --> array
– 即, country --> customer --> purchased
。
我用来确定一个国家在country
字典中是否存在的代码是:
If Not dataset.Exists(country) Then ...
但是,看起来像下面的代码不起作用:
If Not dataset.Exists(country)(customer) Then ....
你如何检查下一级的字典条目? 这是一个国家字典存储在一个数组的内容,然后检查(这似乎是一团糟)的情况下?
你可以使用这个:
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