Copy and past the not equal value using macro

Solved/Closed
ctran123 Posts 2 Registration date Wednesday January 21, 2015 Status Member Last seen March 3, 2015 - Updated on Nov 12, 2018 at 12:52 AM
 Sam - Jul 10, 2017 at 08:36 AM
Hi guys!! Please help me with this.
I'm trying to compare two sheets in excel. If it is NOT a match then copy the entire row into a new third sheet.



Compare

Sheet 1 column C to Sheet 2 column E, if the numbers NOT match copy the entire row of matching sheet 1 column C data to a third Sheet 3.

Any help would be appreciated

Thanks!
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

1 response

Thanks for the sample code it really helps.
I made a few changes for you.


Sub runme2()
Dim lRow As Long, lastRowE As Long

Sheets("Sheet1").Select
lRow = Sheets("Sheet1").Range("C" & Rows.Count).End(xlUp).Row
lastRowE = Sheets("Sheet2").Range("E" & Rows.Count).End(xlUp).Row

For Each cell In Range("C2:C" & lRow)
On Error GoTo docopy
r = Rows(Application.Match(cell.Value, Sheets("Sheet2").Range("E1:E" & lastRowE), 0)).Row
Next
Exit Sub

docopy:
cell.EntireRow.Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
Resume Next
End Sub
2
ctran123 Posts 2 Registration date Wednesday January 21, 2015 Status Member Last seen March 3, 2015
Jan 21, 2015 at 08:05 PM
Thanks you so much.
it works perfectly !!!!
0
I was expecting this, thanks for sharing this one
0