Find duplicates in worksheet
Posted by unstuck2 on July 18, 2001 10:51 AM
Hi,
I need a method for locating and flaging, removing or copying out duplicates in a list.
After a search the method listed in the following post in the archives is very close to what I need:
Re: Compare to find duplicates within worksheet - David Hawley 04:46:13 05/16/01 (1)
Sub CopyUniquesToNewSheet()
'Written by OzGrid Business Applications
'www.ozgrid.com
''''''''''''''''''''''''''''''''''''''''''
'Create a Worksheet
'Extract unique entries only
'Then copy the entire rows to
'the new sheet
''''''''''''''''''''''''''''''''''''''''''
Dim RUniqueCells As Range
'Add a new sheet and name it
'If already exists then rename it
On Error Resume Next
Sheets.Add().Name = "Unique Copies"
If ActiveSheet.Name <> "Unique Copies" Then
ActiveSheet.Name = "Unique Copies" & Sheets.Count
End If
On Error GoTo 0
With Sheet1
'Set Range variable to all entries
Set RUniqueCells = Range(.Range("A1"), .Range("A65536").End(xlUp))
'Advance filter to remove duplicates
RUniqueCells.AdvancedFilter _
Action:=xlFilterInPlace, unique:=True
.UsedRange.SpecialCells(xlCellTypeVisible).Copy _
Destination:=ActiveSheet.Range("A1")
.ShowAllData
End With
Application.CutCopyMode = False
'Release memory
Set RUniqueCells = Nothing
End Sub
My question is this:
How do I modify the macro routine so that it searches the active sheet and not just sheet1.
Also, is it possible to modify the macro so that it "asks" which column to search for duplicates in.
The current macro defaults to searching in column A only.
thanks