If Duplicate Copy

soidog

New Member
Joined
May 26, 2016
Messages
45
I have names in Col(A) and data in col(B:R). No duplicates in Col(A).
Col(B) are dates
Col(E:K) have data from 2017
Col(L:R) have data from 2016
I import new data (for 2017) to Col(Z:AG)
After processing new data, it's transfered to Col(A:K), last row + 1
Now I have many duplicates in Col(A) and some of the names from Col(Z) are new.
I want to do two things:
1. If there is a duplicate name in Col(A): copy oldest row, range(L:R) and paste it at newest row, range(L:R).
2. If there is a new name in Col(A): cells in range(L:R) = 0


I have struggle with this for a few days now but I can't get it to work
This is what I have so far:

Code:
Sub Macro1()
'http://www.mrexcel.com/forum/excel-questions/632244-copy-row-if-duplicate-column-using-vba.html


Dim Cell        As range
Dim MyData      As range
Dim LROW        As Long
Dim LstRow      As Long
Application.ScreenUpdating = False


LstRow = ActiveSheet.range("A" & Rows.Count).End(xlUp).Row
Set MyData = range("A5:A" & LstRow)


    For Each Cell In MyData
        If Evaluate("COUNTIF(" & MyData.Address & "," & Cell.Address & ")") > 1 Then
            LROW = cells(Rows.Count, "L").End(xlUp).Row
            range("L" & Cell.Row & ":R" & Cell.Row).Copy Destination:=range("L" & LROW + 1 & ":R" & LROW + 1)
        Else
        range("L" & LROW + 1 & ":R" & LROW + 1) = 0
        End If
    Next Cell
    
Application.ScreenUpdating = True
End Sub

Any help is much appreciated.
Thank you in advance.
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Maybe I should add that all dates in Col(B) are older than today.
Only transfers from Col(Z:AG) have today's date in Col(B).
 
Upvote 0

Forum statistics

Threads
1,223,902
Messages
6,175,278
Members
452,629
Latest member
SahilPolekar

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