Quicker Dupe Deleter VBA Help

Snaps

New Member
Joined
Nov 11, 2010
Messages
29
I'm currently using the following code to delete out any records that duplicate themselves in the A Column. I have lists that are thousands of rows long and when it runs it takes much longer than I would like. Was hoping there was a solution out there that was more efficient.

Using Excel 2003

** Sometimes I use multiple pieces of criteria (various columns) to delete dupes. This code is based solely on the A Coulmn.

Thanks again

Code:
Sub DupeDeleter()
x = ActiveCell.Row
y = x + 1
Do While Cells(x, 1).Value <> ""
Do While Cells(y, 1).Value <> ""
If (Cells(x, 1).Value = Cells(y, 1).Value) Then
Cells(y, 1).EntireRow.Delete
Else
y = y + 1
End If
Loop
x = x + 1
y = x + 1
Loop
End Sub
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Try

Code:
Sub DupeDeleter()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("A" & Rows.Count).End(xlUp).Row
For i = LR To 2 Step -1
    With Range("A" & i)
        If WorksheetFunction.CountIf(Columns("A"), .Value) > 1 Then .EntireRow.Delete
    End With
Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
You are my hero

Thank you very much for that.

I'm a VBA novice so if I wanted to remove dupes based on Coulmns A & C how would the code change?

I believe if I had that knowledge I could edit it for any dupe application.
 
Upvote 0
Try this with a copy of your sheet

Code:
Sub DupeDeleter()
Dim LR As Long, i As Long
Application.ScreenUpdating = False
LR = Range("A" & Rows.Count).End(xlUp).Row
Columns("A").Insert
Range("A1:A" & LR).Formula = "=B1&""_""&D1"
For i = LR To 2 Step -1
    With Range("A" & i)
        If WorksheetFunction.CountIf(Columns("A"), .Value) > 1 Then .EntireRow.Delete
    End With
Next i
Columns("A").Delete
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,590
Messages
6,179,763
Members
452,940
Latest member
rootytrip

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