Compare 2 columns and extract numbers where no exact match

Henner

Board Regular
Joined
May 16, 2002
Messages
174
Hi,

In book1.xls:
Column A contains 34,000 manufacturer part numbers
Column B contains 27,000 manufacturer part numbers.

Could someone please provide me with macro code that will look for an exact match of the part numbers in B with the part numbers in A, and then list in column C all the part numbers in column A that DO NOT exist in column B.

Thanks.

Best regards,
Paul
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

brian.wethington

Well-known Member
Joined
Jul 20, 2006
Messages
1,739
This will list the values that are in A but not in B... I am not sure if you wanted to put the matching in A and be on the same row.

Code:
Sub Test2()
Dim Lst As Long, Ce As Range, Nxt As Long

Application.ScreenUpdating = False
Lst = Cells(Rows.Count, "A").End(xlUp).Row
For Each Ce In Range("A2:A" & Lst)
    If WorksheetFunction.CountIf(Range("B:B"), Ce.Value) = 0 Then
        Nxt = Cells(Rows.Count, "C").End(xlUp).Row + 1
        Cells(Nxt, "C").Value = Ce.Value
    End If
Next Ce
Application.ScreenUpdating = True

End Sub

Hope this helps!
 

Henner

Board Regular
Joined
May 16, 2002
Messages
174
Hi Brian,

Wow, that works perfectly!

Thank you very much indeed for your help and for replying so quickly.


Best regards,
Paul
 

Forum statistics

Threads
1,181,648
Messages
5,931,213
Members
436,784
Latest member
amuljono

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
Top