Macro to compare cells

Richyog

New Member
Joined
Sep 6, 2011
Messages
15
Hi,

I want a macro to compare two columns in two different sheets.

Suppose:-
Sheet1 in column "A" contains a
b
c
d

and Sheet2 in column "A" contains a
b
c
d
e
now i want that my macro should compare these two columns and different cell should be put in the third sheet

or different cell "e" should automatically gets pasted below the "d" in sheet1
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
No reply...............:(

Maybe:

Code:
Sub Richyog()
Dim lr As Long

lr = Cells(Rows.Count, 1).End(xlUp).Row

With Sheets("Sheet2")

    Columns("B:B").Insert shift:=xlToLeft
    
        With Range("B2:B" & lr)
        
            .Formula = "=VLOOKUP(A2,Sheet1!$A$2:$A$1000,1,false)"
            .Value = .Value
            .Replace What:="#N/A", Replacement:="Copy", Lookat:=xlWhole
            .AutoFilter Field:=1, Criteria1:="Copy"
            .SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp)(2)
            .AutoFilter
            .AutoFilter
            
        End With
        
    Columns("B:B").Delete shift:=xlToRight
    
End With

End Sub
 
Last edited:
Upvote 0
Try:
Code:
Sub ins()
Set ws1 = Sheets(1)
Set ws2 = Sheets(2)
lr = ws1.Cells(Rows.Count, 1).End(xlUp).Row
With WorksheetFunction.Application
For Each cell In ws2.Range("A1:A10")
    If IsError(.Index(ws1.Range("A1:A10"), .Match(cell, ws1.Range("A1:A10"), 0), 1)) Then
        ws1.Range("A" & ws1.Cells(Rows.Count, 1).End(xlUp).Row + 1).Value = cell
    End If
Next
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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