siasarma

New Member
Joined
Sep 20, 2008
Messages
46
I have two lists, both on separate sheets. They both contain ID numbers, but with different data in them. I want to know if there is a way to create a macro that will look up the id number in sheet 1, see if there is a matching one in sheet 2, if there is leave it alone. If there isn't I want it to delete all the ones that are not in sheet 1. Let me try to explain that better as that seemed very confusing. In sheet 1 I have 400 numbers. In sheet 2 I have 65,000. I want sheet 2 to end up with the 400 that are in sheet 1. So it needs to look through all the 400 on sheet 1 and delete any that are extras in sheet 2.

Or maybe this would be an easier way. If it could select in sheet 2 all the matches from sheet 1 and copy them all and paste them to a sheet 3. That would work also...any help???
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
1) Sort Sheet1 ascending on the ID column (assume first column)
2) Add a column in second sheet with formula
=VLOOKUP(A1,SHEET1!$A1:A100,1,FALSE)
3) Sort Sheet2 on the new column
4) Delete rows where there is no hit in Sheet1
 
Upvote 0
Hi
Try these macro codes
Code:
Sub siasarma()
Dim x As Long, y As Long, d As Long, a As Long, b As Long
x = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
y = Sheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
d = Sheets("Sheet2").Cells(2, Columns.Count).End(xlToLeft).Column
For a = 2 To x
For b = 1 To d
Cells(1, 200) = "=vlookup(A" & a & ",sheet2!A2:" & Chr(d + 64) & y & "," & b & ", false)"
Cells(2, 200) = "=iserror(GR1)"
If Cells(2, 200) = False Then
Cells(x + a + 1, b) = Cells(1, 200)
End If
Next b
Next a
End Sub
It looksup ID of sheet1 with sheet2 and returns matching rows and pastes into sheet1. if you are satisfied that it is working properly, you can delete sheet2 after running this macro.
Ravi
 
Upvote 0

Forum statistics

Threads
1,216,739
Messages
6,132,438
Members
449,728
Latest member
teodora bocarski

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