Comparing Two Excel Sheets and copying like data to third sheet

Solved/Closed
coz2992 Posts 1 Registration date Monday June 9, 2014 Status Member Last seen June 9, 2014 - Updated on Dec 19, 2018 at 05:52 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Jun 18, 2019 at 12:15 PM
Hi,

I'm trying to compare two sheets in excel and have matching column data copy the entire row into a new third sheet. Ex: Compare Sheet 1 column C to Sheet 2 column E, if the numbers match, copy the entire row of matching sheet 1 column C data to a third Sheet 3.

Not sure if this is an "If, then" or "Match" function.

Any help would be appreciated

Thanks!
Related:

4 responses

TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552
Updated on Dec 19, 2018 at 05:55 AM
Hi,

So you want to move an entire row of column C data? Haha. I will go with the entire row, ok?

Assuming column A from sheet1 contains data, here is the code:

Sub RunMe()
Dim lRow, x As Long

Sheets("Sheet1").Select
lRow = Range("C1").End(xlDown).Row

For Each cell In Range("C2:C" & lRow)
    x = 2
    Do
        If cell.Value = Sheets("Sheet2").Cells(x, "E").Value Then
            cell.EntireRow.Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
        End If
        x = x + 1
    Loop Until IsEmpty(Sheets("Sheet2").Cells(x, "E"))
Next
    
End Sub


To implement code:

In Excel hit Alt+F11 to open Microsoft Visual Basic window. Go to Top menu Insert > Module. Now paste the code in the big white field. You can now close Microsoft Visual Basic window.

To run the code:

Back at excel hit, Alt+F8 and double-click RunMe.

Best regards!

29
The script above to compare two excel sheets and copy like data to a third sheet works great. What would be the opposite formula? Two compare two excel sheets and copy unlike data to a separate sheet?
0
Plkno > Plkno
Feb 3, 2015 at 08:12 PM
I got it ...

Sub RunMe()
Dim lRow, x As Long

Sheets("Sheet1").Select
lRow = Range("C1").End(xlDown).Row

For Each cell In Range("C2:C" & lRow)
x = 2
Do
If cell.Value = Sheets("Sheet2").Cells(x, "E").Value Then
Exit For
End If
x = x + 1
Loop Until IsEmpty(Sheets("Sheet2").Cells(x, "E"))
cell.EntireRow.Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Next

End Sub
0
Plkno > Plkno
Feb 3, 2015 at 08:41 PM
Cancel that ... it did not work. Thoughts?
0
ecdest2 Posts 1 Registration date Monday June 17, 2019 Status Member Last seen June 17, 2019
Jun 17, 2019 at 12:58 PM
Formula works great but one problem for me, I want to copy data from Sheet2 (not Sheet1). What changes to make?
0
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 552 > ecdest2 Posts 1 Registration date Monday June 17, 2019 Status Member Last seen June 17, 2019
Jun 18, 2019 at 12:15 PM
Hi Ecdest2,

Have you tried changing the reference to Sheet1, near the top of the code, into Sheet2?

Best regards,
Trowa
0