Carmen has attended:
Excel VBA Intro Intermediate course
Copy cell content while duplicate
Hi,
I am trying to do a macro that finds duplicates in colum A and once they are found, it will copy some contents from the second duplicate cell into the first duplicate (in column C) and deleting the entire row after that.
So far I have found out how to detect the duplicates with the code below
Dim LastRowcheck As Long, n1 As Long
Dim DelRange As Range
With Worksheets("qrOUTPUT1")
LastRowcheck = .Range("A" & .Rows.Count).End(xlUp).Row
For n1 = 1 To LastRowcheck
If .Cells(n1, 1).Value = Cells(n1 + 1, 1).Value Then
End If
Next n1
End With
Could you assist with this?
Thank you
RE: copy cell content while duplicate
Hi Carmen
Interesting!
Just a question. Would it be possible to sort the list by the first column in ascending order?
Thanks
Doug
RE: copy cell content while duplicate
Hi again Carmen
If the A column can be sorted here is a solution using a For loop.
The macro starts at the bottom of the list and steps backwards.
Sub Dedupe()
Dim LastRowcheck As Long, n1 As Long
With Worksheets("qrOUTPUT1")
LastRowcheck = .Range("A" & Rows.Count).End(xlUp).Row
For n1 = LastRowcheck To 2 Step -1
If Cells(n1, 1) = Cells(n1 - 1, 1) Then
Cells(n1, 3).Copy Cells(n1 - 1, 3)
Rows(n1).Delete
End If
Next n1
End With
End Sub
I like the way you used the variable Lastcell.
Doug and Jens
Best STL
RE: copy cell content while duplicate
Hi again Carmen
If the A column can be sorted here is a solution using a For loop.
The macro starts at the bottom of the list and steps backwards.
Sub Dedupe()
Dim LastRowcheck As Long, n1 As Long
With Worksheets("qrOUTPUT1")
LastRowcheck = .Range("A" & Rows.Count).End(xlUp).Row
For n1 = LastRowcheck To 2 Step -1
If Cells(n1, 1) = Cells(n1 - 1, 1) Then
Cells(n1, 3).Copy Cells(n1 - 1, 3)
Rows(n1).Delete
End If
Next n1
End With
End Sub
I like the way you used the variable Lastcell.
Doug and Jens
Best STL