excel - Multi-Select ListBox contents to Range -
using vba have created userform various textboxes, comboboxes & listboxes. set once hit submit button (commandbutton1
), various boxes contents fill selected cell on sheet.
private sub commandbutton1_click() sheets("sheet2").range("d4") = textbox1.text sheet2.cells(5, 4) = combobox2.text sheet2.cells(6, 4) = combobox1.text sheet2.cells(7, 4) = textbox2.text sheet2.cells(8, 4) = textbox4.text userform1.hide end sub
i want contents of multiselect listbox same cells (9, 4) - (15, 4) example. how can this? options on multi select list box range insight, barracuda, siena, visio, project.
you can iterate selected items of listbox
, add them array. when have collected selected items, transfer range
. example:
private sub commandbutton1_click() ' code sheets("sheet2").range("c8") = textbox1.text sheets("sheet2").range("c12") = combobox2.text sheets("sheet2").range("f12") = combobox1.text sheets("sheet2").range("f8") = textbox2.text sheets("sheet2").range("f10") = textbox4.text sheets("sheet2").range("c30") = textbox7.text sheets("sheet2").range("f29:f36") = textbox8.text ' code update sheet listbox selections dim ws worksheet dim rng range dim lng1 long dim lng2 long dim str() string set ws = thisworkbook.worksheets("sheet2") set rng = ws.range("f22") ' (9, 4) - (15, 4) lng2 = 0 ' count of selected items lng1 = 0 me.listbox1.listcount - 1 if me.listbox1.selected(lng1) lng2 = lng2 + 1 ' increment counter redim preserve str(1 lng2) ' resize array... str(lng2) = me.listbox1.list(lng1) ' , add selected item end if next lng1 ' transfer range rng.resize(lng2, 1).value = application.transpose(str) ' close form 'unload me userform1.hide end sub
Comments
Post a Comment