Hi TropicalMagic,
Try this:
Option Explicit
Sub Macro1()
Dim lngMyRow As Long, lngLastRow As Long, lngPasteRow As Long, i As Long
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet
Application.ScreenUpdating = False
Set ws1 = ThisWorkbook.Sheets("Sheet1")
Set ws2 = ThisWorkbook.Sheets("Sheet2")
Set ws3 = ThisWorkbook.Sheets("Sheet3")
lngLastRow = ws2.Range("A:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
For lngMyRow = 2 To lngLastRow
If Application.WorksheetFunction.CountIf(ws1.Range("A:A"), CStr(ws2.Range("A" & lngMyRow))) = 0 Then
If Application.WorksheetFunction.CountIf(ws1.Range("B:B"), CStr(ws2.Range("B" & lngMyRow))) = 0 Then
On Error Resume Next 'Surpress error message if there's no data in 'ws3'
lngPasteRow = ws3.Range("A:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
On Error GoTo 0
lngPasteRow = IIf(lngPasteRow = 0, 2, lngPasteRow + 1)
ws2.Range("A" & lngMyRow & ":B" & lngMyRow).Copy Destination:=ws3.Range("A" & lngPasteRow)
i = i + 1
End If
End If
Next lngMyRow
Application.ScreenUpdating = True
If i = 0 Then
MsgBox "There were no unmatched records found in """ & ws2.Name & """ when compared to """ & ws1.Name & """.", vbInformation
Else
MsgBox "The " & Format(i, "#,##0") & " non matching records from """ & ws2.Name & """ compared to """ & ws1.Name & """ have now been copied to """ & ws3.Name & """.", vbInformation
End If
End Sub
Regards,
Robert
Bookmarks