简体   繁体   English

从VBA集合中获得独特的价值

[英]Getting Unique Values From VBA Collection

I have a collection with an array in it. 我有一个带有数组的集合。 Keys are different but values are duplicate.. I want to get unique values from this collection 键是不同的,但是值是重复的。我想从这个集合中获得唯一的值

Here is the sample 这是样本

Dim MyCollection As New Collection


MyCollection.Add Array(A1,txt),A1
MyCollection.Add Array(A2,txt),A2
MyCollection.Add Array(A3,txt),A3
MyCollection.Add Array(A4,txt),A4

MyCollection.Add Array(A5,num),A5
MyCollection.Add Array(A6,num),A6
MyCollection.Add Array(A7,num),A7
MyCollection.Add Array(A8,nu2),A8

MyCollection.Add Array(B1,nu2),B1
MyCollection.Add Array(B2,nu2),B2
MyCollection.Add Array(B3,txt2),B3
MyCollection.Add Array(B4,txt2),B4
MyCollection.Add Array(B5,txt2),B5

I want to get single instance of 'txt', 'num' , 'nu2' and 'txt2' 我想获取'txt', 'num' , 'nu2' and 'txt2'单个实例

the result can be an array of string containing 'txt', 'num' , 'nu2' and 'txt2' 结果可以是包含'txt', 'num' , 'nu2' and 'txt2'的字符串数组

You can transfer your Collection to a Dictionary using this hack: vba: get unique values from array 您可以使用以下技巧将您的收藏集转移到字典中: vba:从数组中获取唯一值

This will remove the duplicates. 这将删除重复项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM