+ Reply to Thread
Results 1 to 10 of 10

Remove duplicates and count their number - faster method needed

  1. #1
    Registered User
    Join Date
    04-18-2011
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2019
    Posts
    90

    Remove duplicates and count their number - faster method needed

    Morning to all :>

    I need to be able to remove all duplicates from a sheet, keep only 1 record of those duplicates and know how many duplicates there we're in total for each duplicate found. I can already do all this, but my method is painfully slow.

    I attached a file so that u can get the idea better.

    I use 2 macros

    One is to sort my data in ascending order for columns "A:B" (done it with record macro)

    Please Login or Register  to view this content.
    and the main macro witch does all the work

    Please Login or Register  to view this content.
    As I said the macro works fine, but it sooooo very slow.

    Sheet 1 contains the raw data and in Sheet 2 I've run the macro so u can see an example. (As a bonus maybe u can tell me why "C270" is there)
    Attached Files Attached Files
    Last edited by ciprian; 05-02-2011 at 07:43 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Remove duplicates and count their number - faster method needed

    In this case sorting the data isn't necessary.
    Please Login or Register  to view this content.
    Last edited by snb; 05-02-2011 at 07:29 AM.



  3. #3
    Registered User
    Join Date
    10-22-2007
    Location
    Mumbai, India
    MS-Off Ver
    MS Excel 2007
    Posts
    59

    Re: Remove duplicates and count their number - faster method needed

    Hi snb,

    Let me tell you that you wrote a very strong (clever) code however somehow when i am trying the same it is not giving me the expected numbers. What i was trying to do to cross check the accuracy is i tried pivoting the raw dump and counted the number of instances of a particular value and the numbers doesn't match.

    Hi Ciprian,

    Although snb provided a wonderful code which i think might need a quick mind boggling and a fix which i am sure snb will do it (if he reads this and he doesnt proves me wrong ), i would suggest you to write a simple match formula to see whether there are any duplicate values or not and also you can create a patch which will count the number of duplicate records.

    Let me know if you would need further help on the same.

  4. #4
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Remove duplicates and count their number - faster method needed

    @Roshan

    The code counts the number of instances the combination of the values in column A and column B occurs.
    Does that explain the difference ?
    Last edited by snb; 05-02-2011 at 07:30 AM.

  5. #5
    Registered User
    Join Date
    10-22-2007
    Location
    Mumbai, India
    MS-Off Ver
    MS Excel 2007
    Posts
    59

    Re: Remove duplicates and count their number - faster method needed

    snb,

    Thanks for the explanation however thats exactly what i was trying to explain that it works most of the time however fails in some scenarios.

    If you pick up the attached sheet and just copy the first 200 values from column A and run this code on it. You will see the difference after comparing it with a pivoted data.

  6. #6
    Registered User
    Join Date
    10-22-2007
    Location
    Mumbai, India
    MS-Off Ver
    MS Excel 2007
    Posts
    59

    Re: Remove duplicates and count their number - faster method needed

    snb,

    i got the point, basically the example you have given is only for 200 rows and thats where the confusion was. My mistake sorry .
    Inconvenience caused is regretted

  7. #7
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Remove duplicates and count their number - faster method needed

    I'm glad it's sorted out....

  8. #8
    Forum Expert
    Join Date
    12-23-2006
    Location
    germany
    MS-Off Ver
    XL2003 / 2007 / 2010
    Posts
    6,326

    Re: Remove duplicates and count their number - faster method needed

    For what it's worth, a Pivot Table did a nice job too... ( see attached)
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    04-18-2011
    Location
    Bucharest, Romania
    MS-Off Ver
    Excel 2019
    Posts
    90

    Re: Remove duplicates and count their number - faster method needed

    I know that a Pivot table would to a great job too, but for what i need this is the way to go.

    thank you for the code

  10. #10
    Valued Forum Contributor Sadath31's Avatar
    Join Date
    03-02-2011
    Location
    Dammam, Saudi Arabia
    MS-Off Ver
    Office 365
    Posts
    452

    Re: Remove duplicates and count their number - faster method needed

    the below code is bit faster

    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)

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