Delete duplicate rows

richiwatts

Board Regular
Joined
Aug 27, 2002
Messages
131
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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

tigersden

Board Regular
Joined
Oct 5, 2005
Messages
91
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,114
Messages
5,835,462
Members
430,358
Latest member
zzc1128

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
Top