+ Reply to Thread
Results 1 to 31 of 31

Delete duplicating entries across the worksheet

  1. #1
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Delete duplicating entries across the worksheet

    Hello Experts, I need your expert help to get rid of duplicate entries that are scattered all over the sheet and intend to keep the left-most as a unique value. For example, if there is a name appearing 3 times in the whole data set, I would like to keep the name that appears in the left-most column.

    A small sample is attached for your kind reference and expert look: in the example below, I would like to delete the cell/content B13, D17 & E10.

    I would like to clear the content of the duplicating cells as deleting them by moving the column up wouldn't be much feasible perhaps as it would slow down the things drastically. As some of the files would be large containing over 100k rows so it would be great if only those cells with duplicating entries are cleared and left empty.

    Every column indicates a category a client falls in and the left-most column is the most important category and the right-most is the least important. So if a customer falls in the left-most, middle, and right, I would like to delete the middle and right entries and keep the left one.

    Would be very happy to provide any more information if required. A small sample file is attached. Thank you

    Here is the link "mrexcel.com/board/threads/remove-duplicates.1155914" of the post I made on another forum.
    Attached Files Attached Files
    Last edited by aghaffar82; 12-14-2020 at 04:48 PM. Reason: Cross forum posting link included

  2. #2
    Forum Contributor
    Join Date
    08-26-2016
    Location
    UK
    MS-Off Ver
    O365
    Posts
    260

    Re: Delete duplicating entries across the worksheet

    I have a 5 line macro offering which I can post after adjustments/additions are made according to msg#2

  3. #3
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Hello Sir, I am really sorry for my lack of knowledge, I am trying to submit a link but the forum won't allow me to do so until I post a few messages. I will make sure to follow the rules for any such matter in the future. Thank you

  4. #4
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by p45cal View Post
    I have a 5 line macro offering which I can post after adjustments/additions are made according to msg#2
    Sir I am trying to post the link but perhaps being very new the forum won't allow me to do so.

  5. #5
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Sir I have updated my original post with a truncated link as the forum wasn't allowing me to post the full link so I removed www part and updated it. Thank you

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Delete duplicating entries across the worksheet

    Try this Macro.


    Please Login or Register  to view this content.
    Last edited by mehmetcik; 12-14-2020 at 05:03 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  7. #7
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Sir, this line of code produced a Run-time error 1004 (No cells were found).:
    .SpecialCells(xlCellTypeConstants, 1).Select

    My sample data is in columns A to E but my original data file would span from columns A to AD.
    Regards

  8. #8
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Delete duplicating entries across the worksheet

    Try again.

    I may have corrected an error after you downloaded the macro.

    My code works for the posted sample.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 12-14-2020 at 05:25 PM.

  9. #9
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Yes, it is working without any error now.

    Just a couple of requests, if you could kindly make those amendments would be great:

    1- It is deleting the very last cell of the range (E17 from the sample data) despite it has no duplicates.
    2- The number of rows in each column would vary (column A could have fewer data cells and the other columns in the right could have more) so I hope it won't be an issue.
    3- How can I amend it to cover my range from columns A to AD instead of the current range of A to E.

    Regards

    I am not saying Thank you as you advise not to otherwise I cannot express my gratitude for the help you have already rendered.

  10. #10
    Forum Contributor
    Join Date
    08-26-2016
    Location
    UK
    MS-Off Ver
    O365
    Posts
    260

    Re: Delete duplicating entries across the worksheet

    Please Login or Register  to view this content.
    sorry, work in progress, more to come…
    Last edited by p45cal; 12-14-2020 at 06:23 PM.

  11. #11
    Forum Contributor
    Join Date
    08-26-2016
    Location
    UK
    MS-Off Ver
    O365
    Posts
    260

    Re: Delete duplicating entries across the worksheet

    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.
    Last edited by p45cal; 12-14-2020 at 06:16 PM.

  12. #12
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Sir this line results in a type mismatch error (Run-time error 13):
    For Colm = UBound(myVals, 2) To 2 Step -1

    Here is the macro I tried after adjustment of the range:
    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 12-14-2020 at 09:11 PM. Reason: Use code tags please!

  13. #13
    Forum Contributor
    Join Date
    08-26-2016
    Location
    UK
    MS-Off Ver
    O365
    Posts
    260

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by aghaffar82 View Post
    Sir this line results in a type mismatch error (Run-time error 13):
    For Colm = UBound(myVals, 2) To 2 Step -1
    Look back at the message, it's been updated.

  14. #14
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    This seems to have worked like a charm, I will just double check and then mark this as solution. Will update you shortly. Best Regards & Thank you so much.

  15. #15
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by p45cal View Post
    Please Login or Register  to view this content.
    or
    Please Login or Register  to view this content.


    Both of these codes run correctly but take ages for just about 3000 rows and 20 columns. It took almost an hour and eventually excel crashed.

    Unfortunately, won't be suitable for me as I have to run over 100k rows and if for 3000 rows it resulted in that much time and even crashed without getting the final output.
    And I did not use the last line to delete the cells and move up.

    Is there some other method I could try? Thank you

  16. #16
    Forum Contributor
    Join Date
    08-26-2016
    Location
    UK
    MS-Off Ver
    O365
    Posts
    260

    Re: Delete duplicating entries across the worksheet

    OK, if there are duplicates within column A, do these need to be eliminated too?

  17. #17
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Yes, those ones also need to be eliminated. Only one unique entry is required keeping in consideration that if a duplicate entry occurs the left-most and the top-most to be kept and the rest of them should go. Thank you

  18. #18
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Delete duplicating entries across the worksheet

    Hi, aghaffar82
    Try this:
    Please Login or Register  to view this content.

  19. #19
    Forum Contributor
    Join Date
    08-26-2016
    Location
    UK
    MS-Off Ver
    O365
    Posts
    260

    Re: Delete duplicating entries across the worksheet

    Akuini beat me to it! The only thing different I would have done is to close up the gaps, so with a tweak to Akuini's code.
    I cannot post code without getting an 'access denied' firewall block because this code apparently contains html code (with or without code tags) so here's a picture of the code (ugh!)
    Annotations in the code (well, picture):

    2020-12-15_100954.png
    6 seconds for A1:T139264.

    Do NOT have any conditional formatting present for such a range!
    Last edited by p45cal; 12-15-2020 at 08:20 AM.

  20. #20
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by Akuini View Post
    Hi, aghaffar82
    Try this:
    Please Login or Register  to view this content.
    This thing worked like a space rocket, absolutely marvelous.
    For about 150,000 entries it took just 5 seconds. And when I ran about 30 million entries (1million x 30 columns) it cleared out in about 5 hours and I would say that's just outstanding. Thank you so much to you Sir may you be blessed. Regards

  21. #21
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by p45cal View Post
    Akuini beat me to it! The only thing different I would have done is to close up the gaps, so with a tweak to Akuini's code.
    I cannot post code without getting an 'access denied' firewall block because this code apparently contains html code (with or without code tags) so here's a picture of the code (ugh!)
    Annotations in the code (well, picture):

    Attachment 708791
    6 seconds for A1:T139264.

    Do NOT have any conditional formatting present for such a range!
    Thank you so much Sir, you have been very kind, I will give this code a go to and then let you know how it goes. Best Regards

  22. #22
    Forum Contributor
    Join Date
    08-26-2016
    Location
    UK
    MS-Off Ver
    O365
    Posts
    260

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by aghaffar82 View Post
    This thing worked like a space rocket, absolutely marvelous.
    For about 150,000 entries it took just 5 seconds. And when I ran about 30 million entries (1million x 30 columns) it cleared out in about 5 hours and I would say that's just outstanding. Thank you so much to you Sir may you be blessed. Regards
    5 Hours!!
    I tested it on A1:AD1004092 (30,122,760 entries); less than 1 minute and a half.

  23. #23
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by p45cal View Post
    5 Hours!!
    I tested it on A1:AD1004092 (30,122,760 entries); less than 1 minute and a half.
    Sir, perhaps you have a super-computer I tried again with the updated code you shared in the picture and it's been 10 mins and still working. Not sure how long it would take now but I am assuming it would take the same time as before. Thank you

  24. #24
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    And there is no conditional formatting in my file.

  25. #25
    Forum Contributor
    Join Date
    08-26-2016
    Location
    UK
    MS-Off Ver
    O365
    Posts
    260

    Re: Delete duplicating entries across the worksheet

    There's something else slowing it up; it can't be 200 times slower, mine isn't a super computer.
    What Excel version?

  26. #26
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    It's Excel 365, windows 10 and nothing wrong with the computer, it's pretty fast usually with 8GB Ram (1.8 GHZ) processor. Nothing is in the background and even if other applications like chrome even closed during the time. And the test I did with 5000 rows x 30 columns, it took just 5 seconds but with the heavier file it takes way more time.

    Just for your information, the file is quite huge it has a size of 165 MB and I don't have any clue why that's so huge with that simple text entries, without any formula and conditional formatting and perhaps that's the reason it's that slow. Thank you

  27. #27
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Delete duplicating entries across the worksheet

    1. Is it possible that you have data that exists outside column 1-30 that you're not aware of? so if say you have data in column 500 then the code will process 500 x 1 million cells.
    Try checking the last column with this code:

    Please Login or Register  to view this content.
    2. How many unique values do you have? about 1 million, 10 million or 20 million?
    More unique values means the dictionary is getting bigger so it will take longer to process the data.

  28. #28
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by Akuini View Post
    1. Is it possible that you have data that exists outside column 1-30 that you're not aware of? so if say you have data in column 500 then the code will process 500 x 1 million cells.
    Try checking the last column with this code:

    Please Login or Register  to view this content.
    2. How many unique values do you have? about 1 million, 10 million or 20 million?
    More unique values means the dictionary is getting bigger so it will take longer to process the data.
    Hello, the final Result shows a de-duplicated and unique count of 7.73 million (7,736,330) cells/entries. And the original file has about 13.27 million (13,266,493) cells/entries spanned in 30 columns and the longest column goes at row number 1,004,799. And if I hit ctrl+end the cursor moves in the same row i.e. 1,004,799 in column AD (AD1004799) and there is no data beyond the column AD. The macro also shows the last column = 30. Thank you

  29. #29
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,004

    Re: Delete duplicating entries across the worksheet

    Hello, the final Result shows a de-duplicated and unique count of 7.73 million (7,736,330) cells/entries. And the original file has about 13.27 million (13,266,493) cells/entries spanned in 30 columns and the longest column goes at row number 1,004,799.
    Is it just one time job that you've already finished or are you going to do this again?
    Because it looks like you have a lot of blank cells in the data set, so I think I can make the code faster.
    Let me know if you still need a faster code for this job.
    And thanks for add reputation.

  30. #30
    Registered User
    Join Date
    02-06-2020
    Location
    Lahore, Pakistan
    MS-Off Ver
    365
    Posts
    29

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by Akuini View Post
    Is it just one time job that you've already finished or are you going to do this again?
    Because it looks like you have a lot of blank cells in the data set, so I think I can make the code faster.
    Let me know if you still need a faster code for this job.
    And thanks for add reputation.
    Thank you, dear, yeah, it was a one-time thing for now but may be required to be done in the middle of next year. If those blanks cells are the culprit, I think, first I can find and replace them with a 0 or something alike and see what happens. Thank you

  31. #31
    Forum Contributor
    Join Date
    08-26-2016
    Location
    UK
    MS-Off Ver
    O365
    Posts
    260

    Re: Delete duplicating entries across the worksheet

    Quote Originally Posted by aghaffar82 View Post
    It's Excel 365, windows 10 and nothing wrong with the computer, it's pretty fast usually with 8GB Ram (1.8 GHZ) processor. Nothing is in the background and even if other applications like chrome even closed during the time.
    …snip…
    Just for your information, the file is quite huge it has a size of 165 MB and I don't have any clue why that's so huge with that simple text entries, without any formula and conditional formatting and perhaps that's the reason it's that slow. Thank you
    OK, could you share the file on a file-sharing site (keep it secure with a password required to gain access if it's sensitive, or if you don't want it in the public domain, and supply that password to me/us in a Private Message at this site) or Private Message me here and I'll supply an email address for direct sending.

    I'm very hopeful we can make this fast for you, one way or another…

+ 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. Edit/Delete without duplicating the contacts on the worksheet
    By asmita.nda in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-18-2016, 10:58 PM
  2. [SOLVED] Duplicating cell entries
    By JohnnyKarate in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-07-2016, 09:05 AM
  3. [SOLVED] Duplicating Entries
    By eznoh in forum Excel General
    Replies: 20
    Last Post: 01-11-2013, 01:48 PM
  4. formula for finding duplicating entries across worksheet
    By tanglin10 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 01-09-2013, 11:05 PM
  5. Replies: 0
    Last Post: 01-09-2013, 05:28 AM
  6. VLookup Problem - Duplicating Entries
    By JohnathanC in forum Excel General
    Replies: 2
    Last Post: 08-27-2010, 05:03 PM
  7. delete duplicate entries in worksheet
    By longhorn23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-11-2010, 12:55 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