excel vba - Search two specific, nonadjacent columns for value in textbox -
please help. can not figure out how search columns b , j exclusively. searching range b:b through j:j. else works fine.
sub find_item(snfound, snrng, idfound)
'the user prompted input either serial number or unique id number textbox on userform. 'this suppose search columns b (serial number) , j (id number) in table2 number user entered 'everything works except not limiting search columns b , j. searching columns b through j.
dim findsnid string 'note -- snfound , idfound dim boolean, snrng dim range
call resetfilters 'this sub removes filtering active sheet
findsnid = snid_textbox.value if trim(findsnid) <> "" sheets("inventory").range("b:b", "j:j") set snrng = .find(what:=findsnid, _ after:=.cells(.cells.count), _ lookin:=xlvalues, _ lookat:=xlwhole, _ searchorder:=xlbyrows, _ searchdirection:=xlnext, _ matchcase:=false) if not snrng nothing snrng.activate
'if match found in column b (serial number) display msgbox item found , it's self location xxxxxx column w (offset 0,21)_ 'and it's current status either available or checked out (offset 0,23)
if snrng.column = 2 msgbox "a matching serial number found in location " & snrng.offset(0, 21).value & vbcrlf & _ "it's current status " & snrng.offset(0, 23).value areabox2.value = snrng.offset(0, 28).value sectionbox2.value = snrng.offset(0, 29).value shelfbox2.value = snrng.offset(0, 30).value snfound = true idfound = false end if
'if match found in column j (id number)then item's shelf location , status displayed.
if snrng.column = 10 msgbox "a matching id number found in location " & snrng.offset(0, 13).value & vbcrlf & _ "it's current status " & snrng.offset(0, 15).value areabox2.value = snrng.offset(0, 28).value sectionbox2.value = snrng.offset(0, 29).value shelfbox2.value = snrng.offset(0, 30).value snfound = false idfound = true end if end if end end if
end sub
try creating range setting range variable = union(range("b:b"), range("j:j"))
Comments
Post a Comment