Unique values in combo box in excel vba -
i got unique value in combo box1 , want add unique values in combobox2 combobox1 items matching.
eg: if select combobox1 test "india", should language in combobox2.
the data saved in excel product
dim ws worksheet dim rcell range set ws = worksheets("product") '//clear combobox combobox1.clear createobject("scripting.dictionary") each rcell in ws.range("a2", ws.cells(rows.count, "a").end(xlup)) if not .exists(rcell.value) .add rcell.value, nothing end if next rcell combobox1.list = .keys end
try this
'on userform initialization event fill combobox1 uniq items "a" private sub userform_initialize() dim ws worksheet, rcell range, key dim dic object: set dic = createobject("scripting.dictionary") set ws = worksheets("product") userform1.combobox1.clear each rcell in ws.range("a2", ws.cells(rows.count, "a").end(xlup)) if not dic.exists(lcase(rcell.value)) dic.add lcase(rcell.value), nothing end if next rcell each key in dic userform1.combobox1.additem key next end sub 'on combobox1 click event fill combobox2 uniq items column "b", 'where selected combobox1.value matched cell value in column "a". 'you can change event combobox1_enter() or combobox1_change() or 'another event depending on needs private sub combobox1_click() dim rcell range, key dim dic object: set dic = createobject("scripting.dictionary") set ws = worksheets("product") userform1.combobox2.clear each rcell in ws.range("a2", ws.cells(rows.count, "a").end(xlup)) if rcell.value = combobox1.value if not dic.exists(lcase(rcell.offset(, 1).value)) dic.add lcase(rcell.offset(, 1).value), nothing end if end if next rcell each key in dic userform1.combobox2.additem key next end sub output result

Comments
Post a Comment