VBA Help PLS! Compare two lists and output unmatched items

Xceller

Active Member
Joined
Aug 24, 2009
Messages
265
Thank you in advance!

Hi - I have two lists that I have compare to compare.
expected result:
Mark items matched in next to them, output unmatched items in column "J"

I started the code below. It properly marks the correct items, but I have trouble outputting them in Column "J"


Sub BNKREC()

Counter = 0
For i = 3 To 9
For J = 3 To 6
If Cells(i, "B").Value = Cells(J, "F").Value And Cells(i, "C").Value = Cells(J, "G").Value Then
Cells(i, "D").Value = "X"
Cells(J, "H").Value = "X"
Else
Range("J1").Offset(Counter, 0).Value = Cells(i, "B").Value
End If
Counter = Counter + 1
Next
Next

End Sub




List 1:
Date Check# Amount
03/02/2013 100 $1,000.00
03/03/2013 101 $1,045.25
03/05/2013 102 $280.56
03/06/2013 103 $456.31
03/08/2013 104 $250.55
03/15/2013 105 $2,456.12
03/25/2013 106 $844.76

List 2:
Date Check# Amount
03/02/2013 100 $1,000.00
03/05/2013 102 $280.56
03/08/2013 104 $250.55
03/25/2013 106 $844.76


Expected result:

Un-Matched List:
03/03/2013 101 $1,045.25
03/06/2013 103 $456.31
03/15/2013 105 $2,456.12
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try this:
Code:
Sub UnmatchedList()
Dim lR1 As Long, lR2 As Long, nRU As Long, Matched As Boolean
Dim vA1 As Variant, vA2 As Variant
'Assume first list starts in A2 - adjust to suit
lR1 = Range("A" & Rows.Count).End(xlUp).Row
'Assume 2nd list starts in F2 - adjust to suit
lR2 = Range("F" & Rows.Count).End(xlUp).Row
'Assume unmatched output starts in K2 - adjust to suit
Range("K1:M1").Value = Range("A1:C1").Value
vA1 = Range("A2", "C" & lR1).Value
vA2 = Range("F2", "H" & lR2).Value
Application.ScreenUpdating = False
For i = LBound(vA1, 1) To UBound(vA1, 1)
    Matched = False
    For j = LBound(vA2, 1) To UBound(vA2, 1)
        If Join(Array(vA1(i, 1), vA1(i, 2), vA1(i, 3)), "") = _
            Join(Array(vA2(j, 1), vA2(j, 2), vA2(j, 3)), "") Then
            Matched = True
            Exit For
        End If
    Next j
    If Not Matched Then
        nRU = Range("K" & Rows.Count).End(xlUp).Row + 1
        Range("K" & nRU).Resize(1, 3).Value = Array(vA1(i, 1), vA1(i, 2), vA1(i, 3))
    End If
Next i
End Sub
 
Upvote 0
Hi JoeMo,

Thanks for the quick response. I tried your code. It just copied the whole List1 to Range K1:M8
 
Upvote 0
Range for list1 = A2:C9
Range for List2 = E2:G6
If you look at the comments in the code I posted, it indicates list2 is assumed to be in F:H ('Assume 2nd list starts in F2 - adjust to suit). You need to adjust the code to your range as indicated in the comment.
 
Upvote 0

Forum statistics

Threads
1,202,909
Messages
6,052,493
Members
444,587
Latest member
ezza59

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