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:
Any help is much appreciated.
Thank you in advance.
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.