vba - Excel User Input, read the database, and put value to listbox -
private sub searchguess_click() thisworkbook.worksheets("wp").range("wp") set rng = .find(what:=textbox1.value, _ lookin:=xlvalues, _ lookat:=xlcontains, _ searchorder:=xlbyrows, _ searchdirection:=xlprevious) if not rng nothing rownumber = rng.row else rownumber = 0 end if end msgbox thisworkbook.worksheets("wp").cells(rownumber, 1).value end sub
i user search or guess string in excel database, whenever type string containing data database, print onto listbox , can select, continue , edit.
any idea how this, above thing can do.
use range.find loop populate array, set .list property of listbox array created:
private sub searchguess_click() dim rngfound range dim arrlist() variant dim arrindex long dim strfirst string me.listbox1.clear thisworkbook.worksheets("wp").range("wp") set rngfound = .find(me.textbox1.text, .cells(.cells.count), xlvalues, xlpart) if not rngfound nothing redim arrlist(1 worksheetfunction.countif(.cells, "*" & me.textbox1.text & "*")) strfirst = rngfound.address arrindex = arrindex + 1 arrlist(arrindex) = .parent.cells(rngfound.row, "a").text set rngfound = .find(me.textbox1.text, rngfound, xlvalues, xlpart) loop while rngfound.address <> strfirst me.listbox1.list = arrlist else msgbox "no matches found [" & me.textbox1.text & "].", , "no results" end if end end sub
Comments
Post a Comment