excel - populating data from userform checkboxes & optional buttons -


i creating userform want able populate values in data tab default values. think have text boxes , combo boxes down, cannot find info on using multiple optional buttons generate data 1 cell depending on selection.example draft

from example, criteria "secondary insurance" how go linking them that, lets cell b1 populated selected option? i'm guessing think checkboxes little more simple, true if checked , false if unchecked. have far code came across fill in cell value of designated text/combo box , going repeat each column need set criteria for.

  private sub commandbutton1_click()     dim lastrow long, ws worksheet      set ws = sheets("sheet1")     lastrow = ws.range("a" & rows.count).end(xlup).row + 1 'finds last blank row     ws.range("a" & lastrow).value = textbox1.text 'adds textbox1 col & last blank row    me.hide end sub 

combobox list

private sub userform_initialize() combobox1.value = ("n/a") combobox1.list = split("n/a yes no") end sub 

please let me know if lack information , or how attach test worksheet, can see picture (i can't on work server). in advance , education.

if caption of option button same want cell text, may want store it:

private sub commandbutton1_click()   dim lastrow range   sheets("sheet1")     set lastrow = .rows(.cells(rows.count, 1).end(xlup).row + 1).cells     if optionbutton1       lastrow(2).value2 = me.optionbutton1.caption     elseif me.optionbutton2       lastrow(2).value2 = me.optionbutton2.caption     else       lastrow(2).value2 = me.optionbutton3.caption     end if   end end sub 

this set desired cell value of caption of option button have selected.

to load data in userform, use this:

sub load_in(row_to_load long)   dim myrow range   sheets("sheet1")     set myrow = .rows(row_to_load).cells     if myrow(2).value2 = optionbutton1.caption       optionbutton1.value = true     elseif myrow(2).value2 = optionbutton2.caption       optionbutton2.value = true     else       optionbutton3.value = true     end if   end end sub 

for this, assumed names hasn't been changed. if nothing selected, third option (n/a) used. same goes loading back. if not want that, change else part elseif looks first 2 options.


Comments