copy data but not the duplicate records

VbaHell

Well-known Member
Joined
Jan 30, 2011
Messages
1,220
Hello all

I hope you can help on this, This code currently inserts a column in column "A" and creates a unique key value
It then copy all the data with the unique key in a sheet called "Comments"

What I need in to copy this data but after the last populate row in "Comments" so it does not overwrite the existing data. Can someone please point me in the right direction on how to do this

Code:
 Columns("A:A").Insert Shift:=xlToRight
    Range("A1").FormulaR1C1 = "Key"
    With Range("A2:A" & LastRow)
        .FormulaR1C1 = "=RC[4]&RC[6]&RC[4]"
        .Value = .Value
    End With
    
    Sheets("Data").Columns("A").Copy Destination:=Sheets("Comments").Columns("A")
    Sheets("Data").Columns("B").Copy Destination:=Sheets("Comments").Columns("B")
    Sheets("Data").Columns("C").Copy Destination:=Sheets("Comments").Columns("C")
    Sheets("Data").Columns("D").Copy Destination:=Sheets("Comments").Columns("D")
    Sheets("Data").Columns("E").Copy Destination:=Sheets("Comments").Columns("E")
    Sheets("Data").Columns("N").Copy Destination:=Sheets("Comments").Columns("F")
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I have solved this now by using this code
Code:
Sub CopyComments()
    Dim Last_Row1 As Long, Last_Row2 As Long
    Dim ws1 As Worksheet, ws2 As Worksheet
    Dim LastRow As Long
    
    Set ws1 = Sheets("Data") ' Change the name of your Sheet
    Set ws2 = Sheets("Comments") ' Change the name of your Sheet
    Last_Row1 = ws1.Range("A" & Rows.Count).End(xlUp).Row ' Determine the lastrow of the data to copy
    Last_Row2 = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1 ' Determine the next empty row in order to paste the data
    ws1.Range("A2:D" & Last_Row1).Copy ws2.Range("A" & Last_Row2)
    ws1.Range("N2:N" & Last_Row1).Copy ws2.Range("F" & Last_Row2)
 
Upvote 0

Forum statistics

Threads
1,215,248
Messages
6,123,866
Members
449,129
Latest member
krishnamadison

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