VBA : Append New Data from one worksheet to another

camgree

New Member
Joined
Jan 15, 2021
Messages
1
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello,

I was using JLGWhiz's code to append entries from a data source to to my target workbook. Currently, it looks from the bottom and removes the duplicates. How would I modify it to preserve the previous entries in the target workbook and add the new entries in order?.

VBA Code:
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, i As Long, fn As Range
Set sh1 = targetWorkbook.Sheets(SheetName) 'Master
Set sh2 = QlikWorkbook.Sheets(1) 'Qlik Data
lr = sh1.Cells(Rows.Count, 1).Row
    For i = 2 To lr 'Assumes header on new sheet.
        With sh2
              Set fn = sh1.Range("A:A").Find(.Cells(i, 1).Value, .Range("A1"), xlValues, xlWhole, xlByRows, xlPrevious)
                If Not fn Is Nothing Then
                    .Cells(i, 1).EntireRow.Copy fn
                End If
        End With
    Next

Thanks,
CG

Original Post : Appending data and removing duplicates
 
Last edited by a moderator:

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
modify the code as

for i = Cells(Rows.Count, 1).End(xlUp).row to lr
 
Upvote 0
Solution

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

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