Advanced Filter VBA problem

ianfrancis56

New Member
Joined
Aug 10, 2011
Messages
34
Hi all,

I am having a problem with Advanced Filter in VBA.

Code:
Sub DataMineTest()
Dim Tgt As Range

    With Sheets(1)
    last = .Range("A2").End(xlDown).Row
    Set Tgt = Sheets(2).Range("A2:A" & Sheets(2).Rows.End(xlDown).Row)
    
        .Range("A2:A" & last).AdvancedFilter Action:=xlFilterCopy, _
        CopyToRange:=Tgt, Unique:=True
    End With
    
End Sub

Column A in Sheets(1) contains position names. I want Advanced Filter to only show the unique values, no duplicates. However, there always seems to be a duplicate.

The example list in Sheets(1) Column A is
Service Support Engineer
Solutions Architect
Project Manager
Solutions Architect
Project Manager
Service Assurance Engineer
Service Automation Engineer
Project Manager
Service Assurance Engineer
Service Automation Engineer
Project Manager
Project Manager
Service Assurance Engineer
Service Automation Engineer
Project Manager
Service Support Engineer
Service Support Engineer
Service Support Engineer
Service Support Engineer
Service Support Engineer

The Advanced Filter results are

Service Support Engineer
Solutions Architect
Project Manager
Service Assurance Engineer
Service Automation Engineer
Service Support Engineer

Any suggestions? Thanks!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
When you do an Advanced filter, the top cell is always considered a header and not part of the Uinque results.

So in this case...
Code:
        .Range("A2:A" & last).AdvancedFilter Action:=xlFilterCopy, _
        CopyToRange:=Tgt, Unique:=True

A2 is the header and may have a diplicate listed below it.

Try something like this...
Code:
 .Range("A1:A" & last).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
 .Range("A2:A" & last).SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets(2).Range("A2")
 
Upvote 0

Forum statistics

Threads
1,224,583
Messages
6,179,678
Members
452,937
Latest member
Bhg1984

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