Public Function findMathingStatements()
Dim s1 As Worksheet, s2 As Worksheet, s3 As Worksheet
Set s1 = Application.ActiveWorkbook.Sheets(1)
Set s2 = Application.ActiveWorkbook.Sheets(2)
Set s3 = Application.ActiveWorkbook.Sheets(3)
highlightColour = RGB(150, 250, 150) ' <------------- You can adjust the highlight colour here
daysInterval = 2 ' <--------- You can adjust the +- allowed days here
lastRow1 = WorksheetFunction.Max(s1.Range("A" & Rows.Count).End(xlUp).Row, s1.Range("B" & Rows.Count).End(xlUp).Row)
lastRow2 = WorksheetFunction.Max(s2.Range("A" & Rows.Count).End(xlUp).Row, s2.Range("B" & Rows.Count).End(xlUp).Row)
lastRow3_1 = WorksheetFunction.Max(s3.Range("A" & Rows.Count).End(xlUp).Row, s3.Range("B" & Rows.Count).End(xlUp).Row)
lastRow3_2 = WorksheetFunction.Max(s3.Range("H" & Rows.Count).End(xlUp).Row, s3.Range("I" & Rows.Count).End(xlUp).Row)
s1.Range("A2:B" & lastRow1).Interior.ColorIndex = xlNone
s2.Range("A2:B" & lastRow2).Interior.ColorIndex = xlNone
s3.Range("A7:B" & lastRow3_1 + 1).ClearContents
s3.Range("H7:I" & lastRow3_2 + 1).ClearContents
For i = 2 To lastRow1
For j = 2 To lastRow2
If s1.Range("B" & i).Value = s2.Range("B" & j).Value Then
d1_text = Replace(s1.Range("A" & i).Value, "/", "")
d2_text = Replace(s2.Range("A" & j).Value, "/", "")
d1 = DateSerial(Right(d1_text, 2), Mid(d1_text, 3, 2), Left(d1_text, 2))
d2 = DateSerial(Right(d2_text, 2), Mid(d2_text, 3, 2), Left(d2_text, 2))
If Abs(DateDiff("d", d1, d2)) <= daysInterval Then
s1.Range("A" & i & ":B" & i).Interior.Color = highlightColour
s2.Range("A" & j & ":B" & j).Interior.Color = highlightColour
End If
End If
Next
Next
For i = 2 To lastRow1
If s1.Range("A" & i & ":B" & i).Interior.Color <> highlightColour Then
lastRow3 = WorksheetFunction.Max(s3.Range("A" & Rows.Count).End(xlUp).Row, s3.Range("B" & Rows.Count).End(xlUp).Row)
s3.Range("A" & lastRow3 + 1 & ":B" & lastRow3 + 1).Value = s1.Range("A" & i & ":B" & i).Value
End If
Next
For i = 2 To lastRow2
If s2.Range("A" & i & ":B" & i).Interior.Color <> highlightColour Then
lastRow3 = WorksheetFunction.Max(s3.Range("H" & Rows.Count).End(xlUp).Row, s3.Range("I" & Rows.Count).End(xlUp).Row)
s3.Range("H" & lastRow3 + 1 & ":I" & lastRow3 + 1).Value = s2.Range("A" & i & ":B" & i).Value
End If
Next
End Function