compare two worksheet

Maheshp

Board Regular
Joined
Jul 29, 2009
Messages
186
i am trying to compare two worksheet sheet1 & sheet2 within same workbook and move Matching values in Matched worksheet & unmatching
values in unmatched sheet, dont understand why below code is not working properly, i will appreciate any help on this

Code:
Sub test()
Dim i As Long
For i = 2 To 10 Step -1
If Sheets("sheet1").Cells(i, 1).Value <> Sheets("sheet2").Cells(i, 1).Value Then
Cells(i, 1).EntireRow.Copy
Sheets("Unmatched").Select
Sheets("Unmatched").Range("A" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
Else
Cells(i, 1).EntireRow.Copy
Sheets("Matched").Select
Sheets("Matched").Range("A" & Rows.Count).End(xlUp).Offset(1).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
End If
Next i
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try

Code:
Sub test()
Dim i As Long
For i = 2 To 10
    If Sheets("sheet1").Cells(i, 1).Value <> Sheets("sheet2").Cells(i, 1).Value Then
        Cells(i, 1).EntireRow.Copy
        Sheets("Unmatched").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
    Else
        Cells(i, 1).EntireRow.Copy
        Sheets("Matched").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
    End If
Next i
Application.CutCopyMode = False
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,582
Messages
6,179,670
Members
452,936
Latest member
anamikabhargaw

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