Comparing 2 Excel spreadsheets [Closed]

Report
Posts
1
Registration date
Monday June 5, 2017
Status
Member
Last seen
June 5, 2017
-
Posts
2674
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
October 27, 2020
-
I have a giant master list of addresses.
I have a second much smaller list of addresses in a specific radius.
I want to compare the data in giant list to data in smaller list and pull the matches from the 1st list - copy all matching rows from 1st spreadsheet to a 3rd spreadsheet.
I found this snippet of code from a closed thread and it almost works. Problem is it copies data from the 2nd spreadsheet instead of the 1st. Need help with this. Thanks in advance for any help.

-J


Sub test()
Dim rng As Range, c As Range, cfind As Range
On Error Resume Next
Worksheets("sheet3").Cells.Clear
With Worksheets("sheet1")
Set rng = Range(.Range("A2"), .Range("a2").End(xlDown))
For Each c In rng
With Worksheets("sheet2")
Set cfind = .Columns("A:A").Cells.Find _
(what:=c.Value, lookat:=xlWhole)
If cfind Is Nothing Then GoTo line1
c.EntireRow.Copy Worksheets("sheet3").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
End With 'sheet 2
line1:
Next c
Application.CutCopyMode = False
End With 'sheet 1


End Sub

1 reply

Posts
2674
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
October 27, 2020
446
Hi Ascule,

Well, then replace sheet1 with sheet2 and vice versa.

Best regards,
Trowa