marionmccaleb
New Member
- Joined
- Sep 26, 2006
- Messages
- 24
I have a long list of names some of which are duplicated once---I want to delete the records of both of these names (not just one which the Filter function will do). How can I do this?
Option Explicit
Sub DeleteDupesDemo()
Dim LstRw As Long, Rng As Range, c As Range, DltRng As Range
With Sheets("Sheet1")
LstRw = .Cells(Rows.Count, "A").End(xlUp).Row
Set Rng = .Range("A1:A" & LstRw)
For Each c In Rng
If WorksheetFunction.CountIf(Rng, c.Value) > 1 Then
If DltRng Is Nothing Then
Set DltRng = c
Else
Set DltRng = Union(DltRng, c)
End If
End If
Next c
If Not DltRng Is Nothing Then DltRng.EntireRow.Delete
End With
End Sub
Hi,i normally add a column next to my data then put a formula such as
=IF(countif($c$2:c2;c2)>1,"dup","unique") then copy all the way down. Filter the sheet and pull all the "dups" then delete.
'to remove all duplicates, first appearance included
'.FormulaR1C1 = "=IF(COUNTIF(R" & FR & "C[1]:R" & LR & "C[1],RC[1])=1,1,"""")"