VBA Advanced filter not working

csilabgirl

Active Member
Joined
Aug 14, 2009
Messages
359
Excel 2002

I have the following code:

Sub RemoveDuplicates()
Range("C2:C100").Copy
Range("D2:D100").PasteSpecial Paste:=xlPasteValues

'Filter out duplicates and copy unique list to "E"

Range("D2", Range("D65536").End(xlUp)).AdvancedFilter _
Action:=xlFilterCopy, CopyToRange:=Range("E2"), Unique:=True
End Sub

The purpose of the code is to remove any duplicate entries and create a new list of unique data. It ALMOST works properly. The only place it does not work is cell D2. If there is another data entry in column D which matches the value in D2, it still shows as duplicated in my final unique list. I have noticed after I run the macro, it renames the range name of cell E2 to "extract". Seems that has something to do with it, but not sure how.

Any ideas on how to amend my code to get rid of this bug would be greatly appreciated!
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
I don't think that can be avoided - Excel assumes you have a column header.
You can code around it after finishing (this is untested as I've just typed it here and not in Excel):

Code:
Dim r as Range
If Cells(2,5) = Cells(3,5) Then
    Set r = Range(Cells(3,5),Cells(3,5).End(xlDown))
    r.Copy Destination:=r.Cells(1).Offset(-1)
    r.Cells(r.Cells.Count).ClearContents
    'Application.CutCopyMode = False
End If
 
Last edited:
Upvote 0
Xenou,

Thank you for the code. If excel requires a header for this function I could probably add one. If am unable to then I will try your code. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,526
Messages
6,179,322
Members
452,906
Latest member
Belthazar

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
Back
Top