Code to copy BEFORE deleting a duplicate row?

rettur

New Member
Joined
Jul 6, 2005
Messages
40
Here’s the code I’m using to delete duplicates. This works fine, but the area I’m stuck on is how to code BEFORE I delete the row.
I need to copy data from cells(i, “BE:BG”) and paste (up one row and several columns to the right) to cells(i, “BK:BM”) and THEN use the code below to delete the dup row.

I’ve only been doing this for a month now so I’m at a loss. Would I use Range.Offset? I understand some individual parts of VBA but integrating them is giving me difficulty. I’ve tried different variations and obviously w/ no success since I’m asking for help.

Code:
Sub DeleteDupes()
Dim i As Integer
Workbooks("EmergContacts.xls").Activate

For i = Cells(Rows.Count, "C").End(xlUp).Row To 1 Step -1
    If WorksheetFunction.CountIf(Range("C:C"), Cells(i, 3)) > 1 Then
       Cells(i, 3).EntireRow.Delete
      End If
Next i

End Sub

Thanks for your help. Oh using excel 2003
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Perhaps try:

Code:
Sub DeleteDupes()
Dim i As Integer

    Workbooks("EmergContacts.xls").Activate

    For i = Cells(Rows.Count, "C").End(xlUp).Row To 1 Step -1
        If WorksheetFunction.CountIf(Range("C:C"), Cells(i, 3)) > 1 Then
            Range("BE" & i).Resize(, 3).Copy Range("BE" & i).Offset(-1, 6)
            Cells(i, 3).EntireRow.Delete
        End If
    Next i

End Sub

Also, you really don't need to specify Column C in this line:
Code:
            Cells(i, 3).EntireRow.Delete

You could use Rows(i).Delete, instead. HTH
 
Upvote 0
Ahh, thats sweet! Thanks Taz. I knew I was close, but didn't realize that I needed to swap the order of rows and columns when using Resize.
 
Upvote 0

Forum statistics

Threads
1,226,532
Messages
6,191,609
Members
453,667
Latest member
JoeH7745

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