excel - VBA realtime filter Listbox through Cell Value -
i have listbox in worksheet , activating clicking specified cells. filter listbox writing on cell. example, if write "asd" on cell, listbox should return lines start "asd" in realtime.
private sub worksheet_change(byval target range) on error resume next if target.value <> "" listbox1 = .listcount - 1 0 step -1 if instr(1, lcase(.list(i, 0)), lcase(target.value)) = 0 , _ instr(1, lcase(.list(i, 1)), lcase(target.value)) = 0 , _ instr(1, lcase(.list(i, 2)), lcase(target.value)) = 0 , _ instr(1, lcase(.list(i, 3)), lcase(target.value)) = 0 .removeitem end if next end end if end sub
i have not working.
can try method - when specific cell changed remove items listbox
, populate matching items source range
:
option explicit private sub worksheet_change(byval target range) dim strfilter string dim rngdata range dim lngcounter long ' check changed cell our specific cell , exit if not if intersect(target, sheet1.range("b1")) nothing exit sub end if 'get reference data range set rngdata = sheet1.range("a1:a12") 'get value of changed cell strfilter = target.value 'clear listbox , add matching items sheet1.listbox1.clear lngcounter = 1 rngdata.rows.count if left(rngdata.cells(lngcounter, 1).value, 1) = target.value sheet1.listbox1.additem rngdata.cells(lngcounter, 1).value end if next lngcounter end sub
for example:
Comments
Post a Comment