gpt4 book ai didi

excel - 检查 VBA 中是否存在嵌套字典键

转载 作者:行者123 更新时间:2023-12-01 19:49:58 27 4
gpt4 key购买 nike

我正在尝试在 Excel VBA 中使用字典的字典。我试图找出嵌套字典是否已有键,如果没有,则添加它。

我的数据如下所示:

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

我想到的数据结构看起来像字典-->字典-->数组——也就是说,国家/地区-->客户-->购买

我用来查找 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

关于excel - 检查 VBA 中是否存在嵌套字典键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21936044/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com