excel - Vba UserForm combobox items don't apear till i click on the userform -
i have command button, when click it, shows customized userform contains combobox items taken sheet cells. user suppose press command userform appears, needs select 1 item list, item sheet name in different workbook, accordingly import data sheet. facing problem: when userform appears, click on combobox shows no items, if click once on userform check combobox again shows items correctly, if click again on userform, combobox items doulbled! if selected item works perfectly. want achieve is: want combobox show items directly without clicking on userform. code this:
in userform:
private sub userform_click() dim mlf workbook dim adad long dim mada string dim lastrow long set mlf = activeworkbooklastrow = sheet3.cells(rows.count, 1).end(xlup).row adad = 1 lastrow mada = sheet3.cells(adad, 1) combobox1 .additem mada end next end sub private sub cmdokay_click() 'verify item selected if me.combobox1.boundvalue = vbnullstring msgbox "you did not choose item!", vbokonly exit sub else msgbox "you have selected " & me.combobox1.boundvalue, vbokonly sheet3.cells(1, 2) = me.combobox1.boundvalue end if unload me end sub
in commandbutton
dim testbook workbook set testbook = thisworkbook set database = workbooks.open(filename:=mypath & myfile) testbook.worksheets("sheet4").range("a1:b5").clear userform1 .caption = "settings of test" end dim lo integer lo = 1 database.sheets.count testbook.sheets("sheet4").cells(lo, 1) = database.worksheets(lo).name next userform1.show
that because telling on click event.
change
private sub userform_click()
to
private sub userform_initialize()
once change this, combobox issue go away.
Comments
Post a Comment