Excel VBA move select items from listbox to a listbox in a differnt form that will be another popup userform -


i have workbook has listbox people can select multiple rows. want take information once selected listbox in new form pop once selected.

i found examples transfer between listboxes in same userform, need moving them between different forms.

this code shows how pass information between 2 user forms on same form. need modify move between 2 different forms. if click submit button , listbox textboxes pops up.

option explicit 'move listbox items in userform 'code dave peterson 'posted on www.contextures.com       private sub btn_moveallleft_click()      dim ictr long      ictr = 0 me.listbox2.listcount - 1         me.listbox1.additem me.listbox2.list(ictr)     next ictr      me.listbox2.clear end sub   private sub btn_moveallright_click()  dim ictr long  ictr = 0 me.listbox1.listcount - 1     me.listbox2.additem me.listbox1.list(ictr) next ictr  me.listbox1.clear end sub   private sub btn_moveselectedleft_click()  dim ictr long  ictr = 0 me.listbox2.listcount - 1     if me.listbox2.selected(ictr) = true         me.listbox1.additem me.listbox2.list(ictr)     end if next ictr  ictr = me.listbox2.listcount - 1 0 step -1     if me.listbox2.selected(ictr) = true         me.listbox2.removeitem ictr     end if next ictr  end sub   private sub btn_moveselectedright_click()  dim ictr long  ictr = 0 me.listbox1.listcount - 1     if me.listbox1.selected(ictr) = true         me.listbox2.additem me.listbox1.list(ictr)     end if next ictr  ictr = me.listbox1.listcount - 1 0 step -1     if me.listbox1.selected(ictr) = true         me.listbox1.removeitem ictr     end if next ictr  end sub  private sub cmdok_click() unload me end sub  private sub userform_initialize()  dim ictr long  me.listbox1     ictr = 1 10         .additem "this test" & ictr     next ictr end  me.listbox2     ictr = 1 10         .additem "this not test" & ictr     next ictr end  me.listbox1.multiselect = fmmultiselectmulti me.listbox2.multiselect = fmmultiselectmulti  end sub 

wherever see me can reference different userform.

for example, have 2 userforms userform1 , userform2. let's our initial listbox, listbox1 on userform1 , contains list of colors. userform1 contains command button, commandbutton1 move selected items userform1 different listbox (also called listbox1) in userform2 next form.

the code in userform1, initial form shown, code on command button this:

private sub commandbutton1_click()      dim integer      = 0 me.listbox1.listcount - 1         if me.listbox1.selected(i) = true             userform2.listbox1.additem me.listbox1.list(i)         end if     next      userform2.show   end sub 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -