Unique values in combobox in Excel VBA -


i want unique values in combobox 2 once select combobox1.

column              column b --------              -------- girls                 hair boys                  hair veg                   water non-veg               water 

once select girls in combobox1 (retrieve column 'a' in excel), should show unique value of 'hair' column 'b' instead of twice in excel.

here basics kind of linked choices :

that implement unique values in combobox1 :

private sub userform_initialize() dim ws worksheet, _     dic object, _     rcell range, _     key 'as string  set ws = worksheets("sheet1") set dic = createobject("scripting.dictionary") 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 

'and there part put uniques values in combobox2 when matches criteria combobox1 :

'when change value of the combobox1, it'll launch code, need refresh in there values proposed in combobox2 own tests.

private sub combobox1_change()  dim ws worksheet, _     dic object, _     rcell range, _     key 'as string  set ws = worksheets("sheet1") set dic = createobject("scripting.dictionary") me.combobox2.clear 'clear added elements me.combobox2.value = vbnullstring 'set active value empty string  '------here need tests------- each rcell in ws.range("b2", ws.cells(rows.count, "b").end(xlup))     if rcell.offset(0, -1) <> me.combobox1.value     else         if not dic.exists(lcase(rcell.value))             dic.add lcase(rcell.value), nothing         end if     end if next rcell  each key in dic     userform1.combobox2.additem key next end sub 

and code third combobox :

private sub combobox2_change()      dim ws worksheet, _         dic object, _         rcell range, _         key 'as string      set ws = worksheets("sheet1")     set dic = createobject("scripting.dictionary")     me.combobox3.clear 'clear added elements     me.combobox3.value = vbnullstring 'set active value empty string      '------here need tests-------     each rcell in ws.range("c2", ws.cells(rows.count, "c").end(xlup))         if rcell.offset(0, -1) <> me.combobox2.value , rcell.offset(0, -2) <> me.combobox1.value         else             if not dic.exists(lcase(rcell.value))                 dic.add lcase(rcell.value), nothing             end if         end if     next rcell      each key in dic         userform1.combobox3.additem key     next     end sub 

Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -