excel - How do I get vba loop result to populate a combobox? -
problem: need search list of worksheets in active workbook , return name of every worksheet has cell value matches search input. names of these worksheets need populate userform combobox duplicates.
partial solution: i've been able reverse-engineer piece of code of above. however, worksheet names populate msgbox duplication. how make result populate combobox instead?
i've been experimenting outputting collection writing results new worksheet, these option still in conceptual phase, have no code post.
update (some code):
public sub finddate() 'find date data on sheets dim ws worksheet dim rngfind range dim mydate string dim firstaddress string dim addressstr string dim findnum integer dim sheetarray(299) integer dim arrayindex integer mydate = inputbox("enter date find") if mydate = "" exit sub each ws in activeworkbook.worksheets 'do not search following sheets ws if ws.name = "cm chapters" goto mynext if ws.name = "cm codes" goto mynext if ws.name = "pcs categories" goto mynext if ws.name = "pcs chapters" goto mynext if ws.name = "pcs code" goto mynext set rngfind = .columns(41).find(what:=mydate, lookin:=xlvalues, lookat:=xlpart, matchcase:=false) if not rngfind nothing firstaddress = rngfind.address findnum = findnum + 1 addressstr = addressstr & .name & vbcrlf ''''original working code ' addressstr = addressstr & .name & " " & rngfind.address & vbcrlf ''''modified remove excess text set rngfind = .columns(41).findnext(rngfind) loop while not rngfind nothing , rngfind.address <> firstaddress end if mynext: end next ws if len(addressstr) '''' original working code ' msgbox "found: "" & mydate & "" " & findnum & " times." & vbcr & _ ' addressstr, vbokonly, mydate & " found in these cells" '''' modified to remove excess text msgbox vbcr & addressstr else: msgbox "unable find " & mydate & " in workbook.", vbexclamation end if end sub
try this
do findnum = findnum + 1 addressstr = addressstr & .name combobox1.additem addressstr 'replace combobox1 combobox name addressstr = addressstr & vbcrlf ' if still want add line feed set rngfind = .columns(41).findnext(rngfind) loop while not rngfind nothing , rngfind.address <> firstaddress
Comments
Post a Comment