Help me Guys. VBA code to Compare a column of two worksheets and updating the unmatched records

Jabes7

New Member
Joined
Jul 13, 2012
Messages
12
Hi all,

Help me a VBA CODE. I have two sheets and the sample design is

Sheet1 Sheet2
ID Name sal ID Sal
100 aaa 1000 100 1000
101 bbb 2000 101 2000
102 ccc 3000 102 3000
103 ddd 4000
104 eee 5000
105 fff 6000



Now i need to compare ID COLUMN(unique column) of two Sheets and find the unmatched records.

And then Update the unmatched records into Sheet2

Similarly it should look like

Sheet1 Sheet2
ID Name sal ID Sal
100 aaa 1000 100 1000
101 bbb 2000 101 2000
102 ccc 3000 102 3000
103 ddd 4000 103 4000
104 eee 5000 104 5000
105 fff 6000 105 6000


Thanks in ADVANCE :)
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Maybe:

Code:
Sub Jabes7()

Dim lr As Long
Dim x As Range

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

Columns("D:D").Insert shift:=xlToRight

With Range("D2:D" & lr)

    .Formula = "=VLOOKUP(A2,Sheet2!$A$2:$B$4,1,FALSE)"
    .Value = .Value
    
End With

For Each x In Range("D2:D" & lr)

    If x.Text = "#N/A" Then
    
        x.Offset(, -3).Copy Sheets("Sheet2").Range("A" & Rows.Count).End(3)(2)
        x.Offset(, -1).Copy Sheets("Sheet2").Range("B" & Rows.Count).End(3)(2)
    End If
    
Next x

Columns("D:D").Delete shift:=xlToLeft

    

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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