+ Reply to Thread
Results 1 to 11 of 11

VBA remove unique, triplicates, quadruplicates, keep duplicates

  1. #1
    Registered User
    Join Date
    06-20-2016
    Location
    Detroit
    MS-Off Ver
    2016
    Posts
    4

    VBA remove unique, triplicates, quadruplicates, keep duplicates

    I am working with a large data set that requires cleaning due to human error. One of the most obvious errors that people make create unique, triplicate, or quadruplicate entries. A proper entry would always be a duplicate.

    I'm looking for some advice (I'm quite new at this) at writing a VBA script to only keep duplicates.

    Here is an example of the kind of manual paring I am doing now.

    UIN Catagory Value
    1001 A 100
    1001 B 50
    1002 A 100
    1002 B 75
    1003 A 80
    1004 A 1
    1004 A 100
    1004 B 25
    1005 A 120
    1005 B 70
    1006 A 120
    1006 A 124
    1006 B 76
    1006 B 75
    1007 A 120
    1007 B 70

    to go to

    UIN Category Value
    1001 A 100
    1001 B 50
    1002 A 100
    1002 B 75
    1005 A 120
    1005 B 70
    1007 A 120
    1007 B 70
    Last edited by Bigdanfoley; 06-20-2016 at 09:58 PM. Reason: Wanted to add example file

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,903

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    Here is a code that I normally use to remove duplicates. I have modified it slightly so that in only removes those that are greater than duplicates. It does delete the whole row.
    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    In a new column, put this formula =COUNTIF(A:A,A1) and copy down

    Filter on this new column, select all and remove only "2". Delete the filtered rows.
    多么想要告诉你 我好喜欢你

  4. #4
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    what you could do...
    create helper column, do a countif to see if there is two UIN then filter based on helper, delete helper column
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

  5. #5
    Registered User
    Join Date
    06-20-2016
    Location
    Detroit
    MS-Off Ver
    2016
    Posts
    4

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    Quote Originally Posted by millz View Post
    In a new column, put this formula =COUNTIF(A:A,A1) and copy down

    Filter on this new column, select all and remove only "2". Delete the filtered rows.
    Quote Originally Posted by humdingaling View Post
    what you could do...
    create helper column, do a countif to see if there is two UIN then filter based on helper, delete helper column



    That has been my main way of cleaning this data up, and I appreciate the confirmation of my solution. I was looking for something that was a bit more elegant. I do very much appreciate the advice.

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2506 Win 11
    Posts
    24,903

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    Since you have now posted an example, I have changed up my code. Try the following

    Please Login or Register  to view this content.

  7. #7
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    Solution in VBA form
    assuming your columns of data is A-C
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-20-2016
    Location
    Detroit
    MS-Off Ver
    2016
    Posts
    4

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    Quote Originally Posted by alansidman View Post
    Here is a code that I normally use to remove duplicates. I have modified it slightly so that in only removes those that are greater than duplicates. It does delete the whole row.
    Please Login or Register  to view this content.
    Very interesting, I'll try playing around with this. This gets me much closer to where I want to be, except that I need it to remove all rows that have triplicates or more, not just the triplicate row. For example: If there are three 1004 rows, all three must be removed.

  9. #9
    Registered User
    Join Date
    06-20-2016
    Location
    Detroit
    MS-Off Ver
    2016
    Posts
    4

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    Quote Originally Posted by humdingaling View Post
    Solution in VBA form
    assuming your columns of data is A-C
    Please Login or Register  to view this content.
    This seems to do the trick pretty well. I'll see if I can get it to work with my larger excel file. Thanks so much!

  10. #10
    Forum Expert
    Join Date
    08-12-2012
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    5,636

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    on larger file
    suggest you add the optimisation lines
    this at start
    Please Login or Register  to view this content.
    and of this at the end
    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: VBA remove unique, triplicates, quadruplicates, keep duplicates

    Another suggestion for the problem as stated.
    No need to turn off and on screen updating etc., which only slows this type of code down.
    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)

Similar Threads

  1. Highlighting sets of duplicates, triplicates, etc
    By Spotniq in forum Excel General
    Replies: 6
    Last Post: 09-16-2015, 01:31 PM
  2. Replies: 0
    Last Post: 03-15-2013, 08:32 AM
  3. [SOLVED] Counting Items in a column that have duplicates, triplicates and more
    By 4hyatts in forum Excel Formulas & Functions
    Replies: 13
    Last Post: 01-26-2013, 08:59 PM
  4. Remove duplicates but not triplicates or more?
    By tuppari in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-09-2012, 08:23 AM
  5. [SOLVED] Duplicates, triplicates and more
    By jfd456 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-11-2012, 10:35 AM
  6. Delete duplicates, triplicates and retaining 1 unique
    By iamreese in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-19-2012, 08:01 AM
  7. formatting duplicates, triplicates and almost matches
    By GRichner in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2009, 06:45 PM

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