excel - Remove value from range populating my listbox -


hello have 2 listboxes. first listbox contains items choose from. after selecting item, user clicks on 'add' command button copy value onto range of second listbox. believe of have seen similar add/remove listboxes.

both listboxes created inserting controls , populated input range of items on hidden worksheet.

here problem: adding names works fine, 'remove' procedure created seems take long time complete since list of items can more 200 items.

i use following code match selected listbox value input range value , clears contents of cell in input range:

sub remove()   dim r long dim al listbox  dim d range dim dd range dim allpick worksheet   set al = worksheets("listbox").listboxes("listselected") set allpick = worksheets("columns") set dd = allpick.range("selectednames")   al     r = 1 .listcount         if .selected(r)             each d in dd                 if d.value = .list(r)                 d.clearcontents                 end if             next d         end if      next r end  end sub 

is there alternative code or structure use doesn't take long complete?

i used find function stated commenters , wrote code below. faster , wanted. however, didn't know put after "if cell nothing then" used calculate. suggestions?

dim r long dim al listbox dim strname string dim names worksheet set names = worksheets("names") set al = worksheets("home").listboxes("selectednames")   al     r = 1 .listcount         if .selected(r)         strname = .list(r)         set cell = names.range("currentnames").find(what:=strname)              if cell nothing                 calculate              else: cell.clearcontents             end if         end if     next r end 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -