+ Reply to Thread
Results 1 to 19 of 19

Macro to remove duplicates from several collums, add specified text and sort

  1. #1
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Macro to remove duplicates from several collums, add specified text and sort

    Hi!

    Can anyone help me to make a macro that do the following:

    1. Add the specified text "'0" at the cells in collum C that has one number less than those who start at 1.
    2. Remove duplicates from the four collums so i'm only left with unique customernumbers along with their names and the date?
    3. Sort the rows from the earliest date first.

    Collum A = Lastname
    Collum B = First and middle name
    Collum C = Customernumber (those with 8 numbers has to have 9 numbers and start with "'0")
    Collum D = Date

    Look at attached file for the example.
    The original file contains over 100.000 rows.
    Attached Files Attached Files
    Last edited by PTLS; 12-09-2021 at 09:49 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Do you have Excel 365 or an earlier version? Please update your profile with whatever it is.

    Does each of the customer number and date need to be unique. This isn't a particularly good example since there are no duoploicate customer numbers.

    Please upload a workbook which does have duplicates and manually add the results you expect. For instance if there were two or more rows with the same customer number but different dates, does that count as two unique records or just one, and if one which of the dates would you expect to see
    Last edited by Richard Buttrey; 12-08-2021 at 10:40 AM.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Quote Originally Posted by Richard Buttrey View Post
    Do you have Excel 365 or an earlier version? Please update your profile with whatever it is.

    Does each of the customer number and date need to be unique. This isn't a particularly good example since there are no duoploicate customer numbers.

    Please upload a workbook which does have duplicates and manually add the results you expect. For instance if there were two or more rows with the same customer number but different dates, does that count as two unique records or just one, and if one which of the dates would you expect to see
    Hi!

    Yeah, I use Excel 365(updated my profile now).

    The customer number needs to be unique, not the date. The same name and customer number can often be found in 2018, aswell as 2019, 2020, 2021 and so on.
    In the updated workbook I added you can see an example in red text.

    Please Login or Register  to view this content.
    remove the oldest date, keep the newest date as the new woorkbook shows.
    Attached Files Attached Files

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,162

    Re: Macro to remove duplicates from several collums, add specified text and sort

    100 000 Rows

    Give this a go...
    Please Login or Register  to view this content.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  5. #5
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Supposed to delete this post, don't know how. sorry
    Last edited by PTLS; 12-09-2021 at 04:54 AM.

  6. #6
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Quote Originally Posted by sintek View Post
    100 000 Rows

    Give this a go...
    Please Login or Register  to view this content.
    Thanks man!
    It works, but my workPC doesn't handle this many rows sadly. Excel crashes when i run the macro.
    I dont really need the names. If i delete collum A and B with the names, can you perhaps make a macro that does the same job but just with customernumbers and the dates?

  7. #7
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,162

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Strange...Runs 1.16 seconds with 100 000 rows this side...

  8. #8
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Quote Originally Posted by sintek View Post
    Strange...Runs 1.16 seconds with 100 000 rows this side...
    Can be my laptop that don't handle it?
    Could you make me a macro that does the same job without name and lastname? Added an example as attachment
    Attached Files Attached Files

  9. #9
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,162

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Re: Macro to remove duplicates from several collums, add specified text and sort

    It still crashes. I get the message "Excel is not responding".
    Even when I tried doing it with only 15.000 rows.
    Last edited by PTLS; 12-09-2021 at 08:07 AM.

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,162

    Re: Macro to remove duplicates from several collums, add specified text and sort

    No need to quote entire posts..It just clutters the thread...Upload said sample with 15000 rows...
    Sure someone will solve for you...

  12. #12
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Thanks for help tho!

    Yeah, hopefully someone will

  13. #13
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,162

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Try this quick...
    Please Login or Register  to view this content.

  14. #14
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Crashes when I try on all rows, but it works when i around 40.000 rows.

  15. #15
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,162

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Upload an equivalent sample to your file ... Only way to test alternatives...

  16. #16
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,516

    Re: Macro to remove duplicates from several collums, add specified text and sort

    PTLS,

    Try
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Re: Macro to remove duplicates from several collums, add specified text and sort

    It worked!! I just had to wait 30min or so while it stood at "Excel is not responding".
    Thanks alot for the help :D

  18. #18
    Registered User
    Join Date
    12-21-2020
    Location
    Norway
    MS-Off Ver
    Office 365
    Posts
    35

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Thanks jindon, but the latest marco from sintek worked

  19. #19
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,162

    Re: Macro to remove duplicates from several collums, add specified text and sort

    Quote Originally Posted by PTLS View Post
    Thanks jindon, but the latest marco from sintek worked
    If you had to wait 30 min for mine to work then ... No...jindon's must be split seconds...

    Edit...I just ran 135000+ rows with Post 13 code and it took 0.57 seconds
    Last edited by sintek; 12-09-2021 at 09:56 AM.

+ 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. [SOLVED] text join formula remove duplicates
    By dorabajji in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 12-01-2021, 10:30 AM
  2. Replies: 6
    Last Post: 11-27-2018, 07:17 AM
  3. [SOLVED] Remove duplicates and if space or text came then stop
    By Sekars in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-05-2016, 05:48 PM
  4. [SOLVED] Concatinate string of text and remove duplicates
    By msmayhugh in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-20-2015, 06:38 PM
  5. [SOLVED] Select rows between Bold text to remove duplicates
    By CharlieRB in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2013, 11:50 AM
  6. remove duplicates based on partial text match
    By smelkin in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 06-16-2011, 09:45 AM
  7. Split number and text into two seperate collums
    By madsff in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-18-2010, 07:12 AM

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