Delete Duplicate Rows

stevenwhickey

New Member
Joined
Apr 4, 2006
Messages
42
Hello,
I want to have the rows in my spreadsheet that have duplicate values in a specific column deleted. How can I do that?

ie...

1
2
3
1

The whole row would be deleted when a duplicate 1 was found. Any ideas??
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Try

Code:
Sub DelDup()
Dim LR As Long, i As Long
LR = Range("A" & Columns.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If WorksheetFunction.CountIf(Columns("A"), Range("A" & i).Value) > 1 Then Rows(i).Delete
Next i
End Sub
 
Upvote 0
that worked perfect, thanks so much. How would I do this based on two columns in the same row having the same value?

1 j
2 h
3 g
4 l
2 h
3 g

the last two would be deleted.
 
Upvote 0
Try

Code:
Sub DelDup()
Dim LR As Long, i As Long
LR = Range("A" & Columns.Count).End(xlUp).Row
For i = LR To 1 Step -1
    If WorksheetFunction.CountIf(Columns("A"), Range("A" & i).Value) > 1 And _
        WorksheetFunction.CountIf(Columns("B"), Range("B" & i).Value) > 1 Then Rows(i).Delete
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,203,690
Messages
6,056,753
Members
444,889
Latest member
ibbara

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