# Delete duplicate rows

#### richiwatts

##### Board Regular
I want to check if there are any doubles in column F and they there is then delete the entire row for any duplicates. I just was to keep the first occurrance. Duplicate rows may not be on top of each other. How would I do that?

Rich

### Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi Rich,
You could try this code below. I found it either on this board or the net but have modified it it a little bit with a message box etc.
Just put this in a module.

Tim

Public Sub DeleteDuplicateRows()
Dim intCol, intX As Integer
Dim lngR, lngN As Long
Dim V As Variant
Dim Rng As Range

Range("F1").End(xlDown).Select
ActiveCell.Offset(0, 0).Select
On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

intCol = ActiveCell.Column

If Selection.Rows.Count > 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If

lngN = 0
For lngR = Rng.Rows.Count To 1 Step -1
V = Rng.Cells(lngR, 1).Value
If Application.WorksheetFunction.CountIf(Rng.Columns(1), V) > 1 Then
Rng.Rows(lngR).EntireRow.Delete
lngN = lngN + 1
End If

Next lngR

'Show User Duplicates have been found
If lngN >= 1 Then
MsgBox lngN & " Duplicate Records have been deleted", vbExclamation, "Duplicate Records Found!"
End If

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
EndMacro:
End Sub

Replies
8
Views
349
Replies
5
Views
390
Replies
1
Views
79
Replies
8
Views
418
Replies
2
Views
70

1,203,618
Messages
6,056,317
Members
444,858
Latest member
ucbphd

### 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.

### Which adblocker are you using?

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

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