excel - Fill a column with UserForm -


i want fill column userform. user has 4 options how column can filled. problem right know is, first option works (2). input-mask wont disappear after click ok-button. chosen option should copied column h , filled automatically. mistakes?

private sub commandbutton1_click()  ' ok button dim emptyrow range dim lastrow long lastrow = cells.specialcells(xlcelltypelastcell).row  worksheets("sheet1").activate set emptyrow = worksheets("sheet1").range("h2:h" & lastrow)  if optionbutton2.value = true     emptyrow.value = "2"      if optionbutton3.value = true         emptyrow.value = "3"          if optionbutton4.value = true             emptyrow.value = "4"              if optionbutton5.value = true                 emptyrow.value = "5"             end if         end if     end if end if  end sub 

give shot.. biggest difference here how if statement written. original code had if statements nested in each other, fine, not work you're trying achieve. statement have written 1 if statement. way can select case statements. i'm keeping code similar original ease of learning.

private sub commandbutton1_click() ' ok button dim emptyrow range, ws worksheet dim lastrow long  set ws = thisworkbook.sheets(1) lastrow = ws.cells(ws.rows.count, "h").end(xlup).row 'a more flexible way find last row set emptyrow = ws.range("h2:h" & lastrow)  if optionbutton2.value = true      emptyrow.value = "2" elseif optionbutton3.value = true      emptyrow.value = "3" elseif optionbutton4.value = true      emptyrow.value = "4" elseif optionbutton5.value = true      emptyrow.value = "5" else: msgbox "no option chosen.", vbokonly, "no option chosen" 'catches no button selected end if  me.hide 'this hides userform. method unload me drops cache  end sub 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -