Report

Copy and Past the not equal value using macro [Solved/Closed]

Ask a question ctran123 3Posts Wednesday January 21, 2015Registration date March 3, 2015 Last seen - Last answered on Jul 10, 2017 at 08:36 AM by Sam
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
See more 
Helpful
+2
plus moins
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
Was this answer helpful?  
ctran123 3Posts Wednesday January 21, 2015Registration date March 3, 2015 Last seen - Jan 21, 2015 at 08:05 PM
Thanks you so much.
it works perfectly !!!!
Sam- Jul 10, 2017 at 08:36 AM
I was expecting this, thanks for sharing this one
Reply

Member requests are more likely to be responded to.

Members can monitor the statuses of their requests from their account pages.

A CCM membership gives you access to additional options.

Not a member yet?

Sign up now. It takes less than a minute and is completely free!