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!
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