Is there any built-in functionality in vba to get unique values from a one-dimensional array? What about just getting rid of duplicates?
If not, then how would I get
No, nothing built-in. Do it yourself:
Scripting.Dictionary
objectFor
loop over your array (be sure to use LBound()
and UBound()
instead of looping from 0 to x!)Exists()
on the dictionary. Add every array value (that doesn't already exist) as a key to the dictionary (CStr()
since keys must be stringsScripting.Dictionary
), also store the array value itself into the dictionary.Keys()
(or Items()
) to return all values of the dictionary as a new, now unique array.