vba:此键已与此集合的元素相关联
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3024529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
vba: This key is already associated with an element of this collection
提问by l--''''''---------''''''''''''
Dim arr As New Collection, a
Dim aFirstArray() As Variant
...some code
For Each a In aFirstArray
arr.Add a, a
Next
i get this error: This key is already associated with an element of this collection
我收到此错误: This key is already associated with an element of this collection
on this line : arr.Add a, a
在这一行: arr.Add a, a
what am i doing wrong?
我究竟做错了什么?
采纳答案by Mike
Some more code?
还有一些代码?
from this what you have all I can tell you is that what your error says. The a
is already in the collection (the key is supposed to be an unique string). BTW. is the a
a string?
从这个你所拥有的我可以告诉你的是你的错误所说的。在a
已经在收集(重点应该是一个唯一的字符串)。顺便提一句。是a
字符串吗?
Or maybe you have some repetition in your array which would try to add 1+ time the same item?
或者,您的数组中可能有一些重复项,会尝试添加 1+ 次相同的项目?