VBA: Check two lists a merge missing rows

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,360
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have two sheets, Sheet1 and Sheet2. Need to merge what's additional on Sheet2 into Sheet1.

The column to look for additional data is column B and when a non-match is found, it should be added to Sheet1.

In this example, the new records from Sheet2 are (in column B): Record 4, Recored E, and Record q.

Before (Sheet1)
A​
B​
C​
1​
Hdr 1​
Hdr 2​
Hdr 3​
2​
First​
Record 2​
$11,907.00​
3​
First​
Record 3​
$10,175.00​
4​
First​
Record 1​
$2,620.00​
5​
Second​
Record C​
$10,544.00​
6​
Second​
Record D​
$9,795.00​
7​
Second​
Record A​
$8,447.00​
8​
Second​
Record B​
$7,885.00​
9​
Third​
Record n​
$10,282.00​
10​
Third​
Record m​
$9,166.00​
11​
Third​
Record o​
$6,197.00​
12​
Third​
Record p​
$1,084.00​

<tbody>
</tbody>

After (Sheet1)
E​
F​
G​
1​
Hdr 1​
Hdr 2​
Hdr 3​
2​
First​
Record 2​
$11,907.00​
3​
First​
Record 3​
$10,175.00​
4​
First​
Record 1​
$2,620.00​
5​
First​
Record 4​
6​
Second​
Record C​
$10,544.00​
7​
Second​
Record D​
$9,795.00​
8​
Second​
Record A​
$8,447.00​
9​
Second​
Record B​
$7,885.00​
10​
Second​
Record E​
11​
Third​
Record n​
$10,282.00​
12​
Third​
Record m​
$9,166.00​
13​
Third​
Record o​
$6,197.00​
14​
Third​
Record p​
$1,084.00​
15​
Third​
Record q​

<tbody>
</tbody>


Source Data (Sheet2)
A​
B​
1​
Hdr 1​
Hdr 2​
2​
First​
Record 1​
3​
First​
Record 2​
4​
First​
Record 3​
5​
First​
Record 4​
6​
Second​
Record A​
7​
Second​
Record B​
8​
Second​
Record C​
9​
Second​
Record D​
10​
Second​
Record E​
11​
Third​
Record m​
12​
Third​
Record n​
13​
Third​
Record o​
14​
Third​
Record p​
15​
Third​
Record q​

<tbody>
</tbody>
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Code:
Sub t()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
    For Each c In sh2.Range("B2", sh2.Cells(Rows.Count, 2).End(xlUp))
        If Application.CountIf(sh1.Range("B:B"), c.Value) = 0 Then
            c.EntireRow.Copy sh1.Cells(Rows.Count, 1).End(xlUp)(2)
        End If
    Next
sh1.UsedRange.Sort sh1.Range("A1"), xlAscending, , sh1.Range("B1"), xlAscending, Header:=xlYes
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,212,927
Messages
6,110,695
Members
448,293
Latest member
jin kazuya

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