Compare two tables

YANECKC

Board Regular
Joined
Jun 13, 2002
Messages
199
I have two tables called sheet1 and sheet2.
The first column is Id-Code in both sheets.
I want to compare table(sheet1)Id-Code to table(sheet2) Id-Code and create three tables.
1. matched
2. unmatched sheet1
3. unmatched sheet2

Thank you for your anticipated response
Yaneckc@aol.com
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Have you tried using the query wizards? I believe you'll find matched and unmatched right there??

Good luck!
 
Upvote 0
The unmatched should be easy by writing a select query. The other two you can hit insert, query, find unmatched query. Make them create a table if you wish.
 
Upvote 0
Sub DoIt()
CurrentDb.Execute ("INSERT INTO [unmatched sheet1] ( [Id-Code] ) SELECT
sheet2.[Id-Code] FROM sheet1 RIGHT JOIN sheet2 ON sheet1.[Id-Code] =
sheet2.[Id-Code] WHERE sheet1.[Id-Code] Is Null")
CurrentDb.Execute ("INSERT INTO [unmatched sheet2] ( [Id-Code] ) SELECT
sheet1.[Id-Code] FROM sheet2 RIGHT JOIN sheet1 ON sheet2.[Id-Code] =
sheet1.[Id-Code] WHERE sheet2.[Id-Code] Is Null")
CurrentDb.Execute ("INSERT INTO [matched] ( [Id-Code] ) SELECT
sheet1.[Id-Code] FROM sheet1 LEFT JOIN sheet2 ON sheet1.[Id-Code] =
sheet2.[Id-Code] WHERE Not sheet2.[Id-Code] Is Null")
End Sub

This code from our friendly neighborhood Batcoder.
 
Upvote 0

Forum statistics

Threads
1,221,490
Messages
6,160,133
Members
451,622
Latest member
xmrwnx89

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