+ Reply to Thread
Results 1 to 8 of 8

VBA to only copy unique records from a filter

  1. #1
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    VBA to only copy unique records from a filter

    Ok I know something like this can be done with code like this:
    Columns("X:X").AdvancedFilter Action:=xlFilterInPlace, Unique:=True

    However the sisuation is slightly more complicated.
    So I have a data sheet in which, lets say, column Y holds project names.
    In column X there a names of persons who lead the project.

    So now I wanted to make a validation in a given cell where a user can choose a project name.
    What the macro then should do is filter the list on chosen project.
    So far so good, but next step would be that he copies the column with names to a certain position so I then can have the macro create a validation on that list of names.

    Still so far this works BUT if a name occurs multiple times I also get the name multiple times in my validation drop-down list.
    And that is ofcourse something I do not want.
    Hence my question to only get the unique records when he pastes the name column to the position were he should make the validation.

  2. #2
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: VBA to only copy unique records from a filter

    You can use the Collection, Code below is well commented. See if you can work with it. Modify to your needs.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: VBA to only copy unique records from a filter

    Thanks for this Mike!
    However this would I think mean rebuilding my macro and whas hoping for a bit simpler and small solution.
    Ofcourse....IF this is possible.....

  4. #4
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: VBA to only copy unique records from a filter

    Can you upload your macro or workbook. It will be easier to see what is going on.

  5. #5
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: VBA to only copy unique records from a filter

    Well this is the macro that works fine although it gives duplicate names....

    Please Login or Register  to view this content.
    Last edited by rpinxt; 08-02-2012 at 09:53 AM.

  6. #6
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: VBA to only copy unique records from a filter

    @rpinxt

    Need to use code tags when posting codes to the forum. Looking at your code I think it will be easier if you can upload the workbook

  7. #7
    Forum Contributor
    Join Date
    07-26-2012
    Location
    Netherlands
    MS-Off Ver
    Excel 2016 Office 365 ProPlus
    Posts
    826

    Re: VBA to only copy unique records from a filter

    sorry about that, fixed that now. However uploading the entire workbook will not be possible as the file contains classified info whitch I can not throw over the www...sorry.
    But this is the entire macro for the part that I want.
    Only other thing is a list with data about project and a column in which the user per project is defined

    ---------- Post added at 04:08 PM ---------- Previous post was at 03:56 PM ----------

    Anyway...I just found out a method that suites my purpose.
    With help of the remove duplicate function in excel 2007 (should have known that option sooner....)
    So this small piece of code fixed my problem:
    Please Login or Register  to view this content.

  8. #8
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: VBA to only copy unique records from a filter

    I understand, see if this will work. I havent tested but I think will work for you.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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