简体   繁体   中英

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'

the result can be an array of string containing 'txt', 'num' , 'nu2' and 'txt2'

You can transfer your Collection to a Dictionary using this hack: vba: get unique values from array

This will remove the duplicates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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