Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

copy cell content while

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Copy cell content while duplicate

Copy cell content while duplicate

ResolvedVersion 2007

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

Unfortunately I cannot sort the column. But let me have a look and let you know if it worked.

Thank you for your reply.

Carmen

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

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Jumping Between Sheets in a Book

PgDn and PgUp keys scrolls up and down a screen page in most applications.

Ctrl+PgDn and Ctrl+PgUp keys jump from one sheet in your workbook to the next, up or down through the pages.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.1 secs.