Pasting data at end of the data range, ignoring uniques

DavidGahan

New Member
Joined
Jan 2, 2019
Messages
1
Hey all,

quick question, if Im having a macro for pasting data from certain sheet (that comes on daily basis) to general sheet and adding multiple data every day to it - I have a formula which is working just fine.

Nevertheless if in that range are data that are already existing, is there a way for the macro to skip these rows? (the ones that entirely match)

my simple macro:

Sub VBA_pasting_at_the_end()
With Sheets("Report")
Range("A2:L1000").Copy
Sheets("Report").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End With
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Try the following macro, change "sheet1" by the name of your sheet


Code:
Sub VBA_pasting_at_the_end_uniques()
    Application.ScreenUpdating = False
    '
    Dim h1 As Worksheet, h2 As Worksheet
    Dim uc As Long, u2 As Long, i As Long
    Dim j As Integer, n As Integer
    Dim cad1 As String
    Dim b As Object
    '
    Set h1 = Sheets("sheet1")  'name of your certain sheet
    Set h2 = Sheets("Report")
    '
    uc = h2.UsedRange.Columns(h2.UsedRange.Columns.Count).Column + 1
    u2 = h2.Range("A" & Rows.Count).End(xlUp).Row
    '
    For i = 2 To u2
        cad2 = ""
        For j = 1 To Columns("J").Column
            cad2 = cad2 & h2.Cells(i, j).Value
        Next
        h2.Cells(i, uc).Value = cad2
    Next
    '
    n = 0
    For i = 2 To h1.Range("A" & Rows.Count).End(xlUp).Row       'check row by row
        cad1 = ""
        For j = 1 To Columns("J").Column
            cad1 = cad1 & h1.Cells(i, j).Value
        Next
        Set b = h2.Columns(uc).Find(cad1, lookat:=xlWhole)
        If b Is Nothing Then
            u2 = h2.Range("A" & Rows.Count).End(xlUp).Row + 1
            h1.Rows(i).Copy
            h2.Range("A" & u2).PasteSpecial Paste:=xlPasteValues
            n = n + 1
        End If
    Next
    h2.Columns(uc).Delete
    Application.ScreenUpdating = True
    MsgBox "Added Records : " & n
End Sub

Regards Dante Amor
 
Upvote 0

Forum statistics

Threads
1,224,819
Messages
6,181,153
Members
453,021
Latest member
Justyna P

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