.find method on a fitlered range

  • the .find method is working well (code below), but when i add a fitler to the search range (below, column aa), i seem to get "funky" results (works 90% plus of the time and then i'll get a wrong return, or i have to search a second time to get the correct results...).


    -i've wondered if sometimes the previous search doesn't get cleared?-i'm still testing...


    ???


    Code
    '...
     For Each c In Worksheets("PT").Range("d8:D" & LastRowPC).Cells 'brand
       ' strSearch = c.Value & c.Offset(0, 1).Value            
     strSearch = usfP.cmbMU & usfP.cmdState & c.Value & c.Offset(0, 1).Value
       Set aCell = oshtsp.Range("aa1:aa" & LastRowsp).Find(What:=strSearch, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False, After:=oshtsp.Range("aa" & LastRowsp))
     '...


    thank you.

  • Re: .find method on a fitlered range


    Perhaps this, but it's untested


    Code
    For Each c In Worksheets("PT").Range("d8:D" & LastRowPC).SpecialCells(12) 'brand
         ' strSearch = c.Value & c.Offset(0, 1).Value
        strSearch = usfP.cmbMU & usfP.cmdState & c.Value & c.Offset(0, 1).Value
        Set aCell = oshtsp.Range("aa1:aa" & LastRowsp).Find(What:=strSearch, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False, After:=oshtsp.Range("aa" & LastRowsp))
         '...
  • Re: .find method on a fitlered range


    basically, i have a "master" list (update infrequently) in one sheet...


    i have a promo list in another sheet (frequent updates-doesn't contain all master info.)...


    so, i use the .find from the items in the promo list to search the "master" and retain info. to add to the promo...
    (works well without the filtering)


    make sense?


    thank you.

  • Re: .find method on a fitlered range


    well (finally back to this...)


    i added (.SpecialCells(xlCellTypeVisible)): (and error out on this line "method not correct..."

    Code
    Set aCell = oshtsp.Range("ac2:ac" & LastRowsp).SpecialCells(xlCellTypeVisible).Find(What:=strSearch, LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False, After:=oshtsp.Range("ac" & LastRowsp))


    ?is the syntax correct?
    (n.b., i only want to use the .fiind method on a filtered worksheet...)


    thank you.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!