Range.Find Multiple Criteria

moonlight22

New Member
Joined
Aug 15, 2014
Messages
24
Hi,

Is there a way to use the Range.Find to look for multiple criteria instead of just one value, and not withing a consecutive range, but multiple columns across rows?

I'm assuming it can be accomplished by using the "AND" but I don't know where to place it in the function.

In my case I have 4 values in one tab (Controlsheet) in the range I12:I15. These values are found in another tab (Datasheet), withing the following columns: B, F, I & J.

My current formula looks like this....but this was when i was only looking for one value in M:M

Code:
    Rng = Sheets("DataSheet").Range("M:M").Find(CriteriaValue, Sheets("DataSheet").Range("M1"), xlValues, xlWhole)

Any help is much much appreciated!:)
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
The find method doesn't support multiple criteria in its search. You could .Find one criteria in a loop and test the other three criteria for each match found until all four match.

Code:
    Dim Found As Range, Firstfound As String
    Dim rngSearch As Range
    Dim Criteria As Variant
    
    Set rngSearch = Sheets("DataSheet").Range("B:B")
    
    Criteria = Sheets("ControlSheet").Range("I12:I15").Value
        
    Set Found = rngSearch.Find(What:=Criteria(1, 1), _
                               LookIn:=xlValues, _
                               LookAt:=xlWhole, _
                               SearchOrder:=xlByRows, _
                               SearchDirection:=xlNext, _
                               MatchCase:=False)
        
    If Not Found Is Nothing Then
        
        Firstfound = Found.Address
        
        Do
            If Found.EntireRow.Range("F1").Value = Criteria(2, 1) And _
               Found.EntireRow.Range("I1").Value = Criteria(3, 1) And _
               Found.EntireRow.Range("J1").Value = Criteria(4, 1) Then Exit Do 'Match found
            
            Set Found = rngSearch.FindNext(After:=Found)
            If Found.Address = Firstfound Then Set Found = Nothing
            
        Loop Until Found Is Nothing
        
    End If
    
    If Not Found Is Nothing Then
        Application.Goto Found.EntireRow
    Else
        MsgBox "Nothing matched all four criteria. ", , "No Match Found"
    End If
 
Upvote 0
The find method doesn't support multiple criteria in its search. You could .Find one criteria in a loop and test the other three criteria for each match found until all four match.

Code:
    Dim Found As Range, Firstfound As String
    Dim rngSearch As Range
    Dim Criteria As Variant
   
    Set rngSearch = Sheets("DataSheet").Range("B:B")
   
    Criteria = Sheets("ControlSheet").Range("I12:I15").Value
       
    Set Found = rngSearch.Find(What:=Criteria(1, 1), _
                               LookIn:=xlValues, _
                               LookAt:=xlWhole, _
                               SearchOrder:=xlByRows, _
                               SearchDirection:=xlNext, _
                               MatchCase:=False)
       
    If Not Found Is Nothing Then
       
        Firstfound = Found.Address
       
        Do
            If Found.EntireRow.Range("F1").Value = Criteria(2, 1) And _
               Found.EntireRow.Range("I1").Value = Criteria(3, 1) And _
               Found.EntireRow.Range("J1").Value = Criteria(4, 1) Then Exit Do 'Match found
           
            Set Found = rngSearch.FindNext(After:=Found)
            If Found.Address = Firstfound Then Set Found = Nothing
           
        Loop Until Found Is Nothing
       
    End If
   
    If Not Found Is Nothing Then
        Application.Goto Found.EntireRow
    Else
        MsgBox "Nothing matched all four criteria. ", , "No Match Found"
    End If





WONDERFUL !!! THANKS
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,165
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top