Remove Duplicates (Get Uniques) Excel 2007

Vishesh's picture
You can use the following simple procedure to remove duplicates either in place or get uniques at another range. The second parameter of the below procedure is optional. Try this in Excel 2007.
Sub RemoveDups(rngDups As Range, Optional rngTarget As Range)
    If rngTarget Is Nothing Then
        rngDups.RemoveDuplicates Columns:=1, Header:=xlNo
        rngDups.AdvancedFilter Action:=xlFilterCopy, CopyToRange:=rngTarget, Unique:=True
    End If
End Sub
Sub Test()
    Call RemoveDups(ActiveSheet.Range("A1:A10"), ActiveSheet.Range("D1"))
End Sub