+ Reply to Thread
Results 1 to 6 of 6

Extracting Unique Records with Advanced Filter

  1. #1
    Registered User
    Join Date
    04-30-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    38

    Extracting Unique Records with Advanced Filter

    Hi,

    I am trying to extract unique records from a column of data using advance filter. Here is my code:

    LR = shSource.Cells(rows.Count, "F").End(xlUp).Row 'Last row of column F
    shSource.Range("F12:F").AdvancedFilter Action:=xlFilterCopy, _
    CopyToRange:=shSetup.Range("G2"), Unique:=True

    The code works except for one thing. The first record in the source column is included twice in the filtered result. Can anyone explain why this happens? Thank you.

    Also, I would like the unique records to be sorted in ascending /descending order. Can this be done at the sale time as the filtering process - kind of one step? Please let me know. Thank you.

  2. #2
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Extracting Unique Records with Advanced Filter

    You calculate LR, but do not use it. Try replacing:
    "F12:F"
    with:
    "F12:F" & LR
    Gary's Student

  3. #3
    Registered User
    Join Date
    04-30-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Extracting Unique Records with Advanced Filter

    Thanks for noticing but this does not solve the issue of the duplicate first record.

  4. #4
    Forum Expert Jakobshavn's Avatar
    Join Date
    08-17-2012
    Location
    Lakehurst, NJ, USA
    MS-Off Ver
    Excel 2007
    Posts
    1,970

    Re: Extracting Unique Records with Advanced Filter

    Try the macro on the attached workbook and tell us what happens:
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    04-30-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Extracting Unique Records with Advanced Filter

    Unfortunately I cannot download or open the file.

  6. #6
    Registered User
    Join Date
    04-30-2013
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010
    Posts
    38

    Re: Extracting Unique Records with Advanced Filter

    I have figured it out. Apparently Excel treats the top row, first cell specified in this case, as a header, and does not consider whether they are duplicated in the data below. If the data has no headers, that can cause a duplicate being put in the result. The fix is to add a header row, with unique headers for every column. So I changed the line

    shSource.Range("F12:F").AdvancedFilter Action:=xlFilterCopy, _

    to

    shSource.Range("F11:F").AdvancedFilter Action:=xlFilterCopy, _

    and no more duplicate values. Thanks for your help y'all. :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1