Delete duplicate rows based on multiple values

sharky12345

Well-known Member
Joined
Aug 5, 2010
Messages
3,422
Office Version
  1. 2016
Platform
  1. Windows
I'm using this to delete rows with duplicate values in column B;

VBA Code:
For a = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
If WorksheetFunction.CountIf(Range("B2:B" & a), Cells(a, 2)) > 1 Then Rows(a).Delete
Next

What I now need to do is delete rows where the value is the same in columns A, B, C, D and E.

Can someone give me an idea of how to adapt the existing code, or indeed something even simpler?

Thank you!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Please try the following on a copy of your workbook & see if it does what you want. I'm assuming you mean that the values are the same across all columns (A-E) in multiple rows.

VBA Code:
Option Explicit
Sub ZapDupes()
    Dim ws As Worksheet, i As Long
    Set ws = Worksheets("Sheet1")       '<-- *** Change to actual sheet name ***
    With ws.Range("A1").CurrentRegion
        .RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5), Header:=xlYes
    End With
End Sub
 
Upvote 0
Solution
Actually, you can lose the dim i bit (was part of something else I was looking at)
VBA Code:
Option Explicit
Sub ZapDupes()
    Dim ws As Worksheet
    Set ws = Worksheets("Sheet1")       '<-- *** Change to actual sheet name ***
    With ws.Range("A1").CurrentRegion
        .RemoveDuplicates Columns:=Array(1, 2, 3, 4, 5), Header:=xlYes
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,744
Messages
6,180,696
Members
452,994
Latest member
Janick

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