8 arrays excel vba dictionary excel-vba
我有一段代码似乎没有做预期的事情.VBA Arrays一定是可变的,但似乎当它们作为某些键的值存储到Dictionary中时,它们不再是可变的.有任何想法吗?
Sub foo()
Dim mydict As New Dictionary
mydict.Add "A", Array(1, 2, 3)
MsgBox mydict("A")(1)
''# The above shows 2, which is fine
mydict("A")(1) = 34
MsgBox mydict("A")(1)
''# The above also shows 2, which is not fine
End Sub
Run Code Online (Sandbox Code Playgroud)
Mic*_*rry 11
看来你还需要设置另一个var来更新数组值.
mArray = mydict.Item(1)
mArray(1) = 34
mydict.Item(1) = mArray
Run Code Online (Sandbox Code Playgroud)