Collect all names in a column and put them in an Array in Excel -
i pretty new excel , vba , need question. thing have column different names of companies, exampla apple, microsoft, asus.. , companies might used several times.
how can populate array in vba contains distinct members of column?
you can use vba collection
not allow duplicates same key:
option explicit sub uniquelist() dim long dim rlist range dim cunique new collection dim afinal() string 'change range depending on size of title (or use named range) set rlist = range("a1:m1") 'loop on every column , add value collection (with unique key) = 1 rlist.columns.count on error resume next cunique.add rlist(1, i), cstr(rlist(1, i)) next 'store value collection array redim afinal(1 cunique.count, 1 1) = 1 cunique.count afinal(i, 1) = cunique(i) next 'use afinal whatever want end sub
Comments
Post a Comment