VBA Range.Find multiple criteria

Status
Not open for further replies.

Pepess

New Member
Joined
Sep 19, 2021
Messages
10
Office Version
  1. 2010
Platform
  1. Windows
Hi,

I need some help with my code..

The program is supposed to match payments according to three criteria: 1) invoice number, 2) date of payment and 3) amount paid.
The program reads each row of Sheet 1, scans all 3 criteria mentioned above and will search for it in Sheet 2 (Bank Statement).
In Sheet 2, the information is located in the following columns:
invoice number: D:D
date of payment: B:B
amount paid*: E:E

*For amount paid I should be actually matching the absolute values, but I didn't manage to do that yet.

My code has some errors when it comes to finding the criteria in Sheet 2. The code stops at the point "FirstFound = Found.Address" with error 438 - "object doesn't support this property or method", but I don't understand what's wrong.
It would be nice if you could give me some feedback.

Thank you in advance!

VBA Code:
Sub find_multiple_criteria()
    'Definition of variables for Sheet Auswertungen
    Dim LastRow As Long
    Dim RgNr As Range                      'invoice number
    Dim rng As Range
    Dim ZD As Date                         'date of payment
    Dim RgBe As Currency                   'amount paid
    
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    Set rng = Range("C2:C" & LastRow)
    
    'Definition of variables to match invoices
    Dim Found As Range, FirstFound As String
    Dim rngSearch As Range
    
    'Iteration through visible rows only
    For Each RgNr In rng.SpecialCells(xlCellTypeVisible)
        MsgBox RgNr
        ZD = Cells(RgNr.Row, 6)
        RgBe = Cells(RgNr.Row, 5)
    
       'Matching the criteria
       Set rngSearch = Sheets("Sheet 2").Range("D:D")
       
       Set Found = rngSearch.Find(What:=RgNr, _
                                  LookIn:=xlValues, _
                                  LookAt:=xlPart, _
                                  SearchOrder:=xlByRows, _
                                  searchdirection:=xlNext, _
                                  MatchCase:=False)
       
       If Not Found Is Nothing Then
       
           FirstFound = Found.Adress
           
           Do
               If Found.EntireRow.Range("B1").Value = ZD And _
                  Found.EntireRow.Range("E1").Value = RgBe Then Exit Do
                  
               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
           matched = Sheets("Sheet 2").Cells(Found.Row, 4)
           Sheets("Auswertungen").Cells(RgNr.Row, 7).Value = matched
       Else
           MsgBox "Nothing matched all three criteria. ", , "No match found"
       End If
  
    Next RgNr
End Sub
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Hi & welcome to MrExcel.
The code stops at the point "FirstFound = Found.Address"
That's not actually what your code is, you have a typo on the word address
 
Upvote 0
Hi & welcome to MrExcel.

That's not actually what your code is, you have a typo on the word address
Thank you Fluff. That happens after working the whole day with the code.
The code is still ignoring the do..until loop, but I may do a new Post
 
Upvote 0
Status
Not open for further replies.

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