+ Reply to Thread
Results 1 to 19 of 19

I have a good macro to delete duplicates, but I want it to keep last one intact

  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    I have a good macro to delete duplicates, but I want it to keep last one intact

    I have a good macro to delete duplicates that is very efficient and fast, At the moment it keeps the first line, but I want it to keep the last line instead. Any help is appreciated. Its a good macro if anyone else wants to use it. Here is the current macro.
    Please Login or Register  to view this content.
    Cheers

    Rain
    Last edited by rain4u; 02-08-2011 at 07:51 PM.

  2. #2
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    try to change this line

    Please Login or Register  to view this content.
    to this

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Everything remained exactly the same. It still keeps the firs line. Any more ideas???

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    I would think it would be:
    Please Login or Register  to view this content.

    It would much simpler to tell you for sure with a small sample file of 10-20 rows with before/after examples of what you're wanting.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  5. #5
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    So far no luck with any offered solutions.Yeah no probs. Here is the file. Please highlight the column A and run the macro.
    Only way to make sure which line it really did keep is by looking column K. The only row left should be with value -4
    Its the last line in my test sheet.

    Please advise what to try next. I'm bit desperate to get it for tomorrow. Have to sort out some reports. Cheers
    Attached Files Attached Files
    Last edited by rain4u; 02-08-2011 at 06:35 PM. Reason: typos

  6. #6
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    from you file: why should 4 and its row be left? As for me the code should leave -7, -6, -5 and 4 and with offered solution (post above) it does it

  7. #7
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    This is how I would do that:
    Please Login or Register  to view this content.


    This version will work based on the current activecell's column:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 02-08-2011 at 07:09 PM.

  8. #8
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Quote Originally Posted by JBeaucaire View Post
    This is how I would do that:
    Thank you Sir! works like a charm.


    As you are so brilliant I have another one for you. You can check that with the same xls.
    Can you give me a macro of conditional formating that would highlight every duplicate as per column A. And I mean every cell in coll A (that includes all the duplicates + one unique). The formulas that I have managed to find on my own initiative a will always keep one cell (either the first cell or the last cell in column) not highlighted. They do that as they consider it unique. I would like that to be highlighted as well. Its just in my reports there could be 3 that are basically the same. I have to work some reports line by line. The order is always by date and im after some parts. The formulas so far will skip one. But i would like to include that please. On my spread sheet every single one should be highlighted on Col A


    Can you help?

  9. #9
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Actually I will close the thread and open a new one Cheers for everybody who contributed. Thank you


    Kind regards
    Rain

  10. #10
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    INCLUDED:
    -- Leave top dupe OR Leave bottom Dupe FROM user msg click
    -- error check for single column selection
    -- msg confirmation of currect row selected

    Please Login or Register  to view this content.

  11. #11
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Hi guys
    I have used this code for a some time now
    Please Login or Register  to view this content.
    But now I need to use column B instead of column A. I tried to do some amendments to the code like the obvious ""A" & Rows.Count" to "B" & Rows. Count but it think i get it wrong and Im missing something as when running the macro it prompts me with error "No cells were found"

    Can someone point me to a right direction. Any help would be great.

  12. #12
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Have you tried the code I've provided ? It allows the user to select a column to base the "dupe check" on.

  13. #13
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    In the R1C1 syntax, C1 means "column 1" or "column A". You need to change those references to C2 for column 2 / column B.
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Hi Nimrod and JBeaucaire

    JBeaucaire, the code now works again. Thank you for that

    Nimrod, Can you please help me to amend your offered code to work without prompting an option to a user of which row to keep. I would be really grateful to have both examples but if you don't ave much time then simply to keep the bottom one would make me happy. Simple reason is that after a test run I realized that your code works brilliantly. I timed both of the codes. The usual code I have used so far takes about 18 seconds with my data. Your code does it within 3 seconds. So can you help me to remove option for the user?


    Cheers

  15. #15
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Replace all this ...

    Please Login or Register  to view this content.

    With this ...

    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Thank you Nimrod. It works very efficiently.
    Please Login or Register  to view this content.
    Interestingly if you remove this section above all together it acts as "no". Just for the as cautionary I have still just replaced with the line as advsied by nimrod.

    How to keep the top duplicate? I have tried the obvious by changing "no" to "yes". It does not work.

    Cheers
    Rain

  17. #17
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Hi
    Watersev
    Can you have a look of the attachment.

    Cheers
    Rain
    Attached Files Attached Files

  18. #18
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    hi, rain4u, please check attachment, run code "test"
    Attached Files Attached Files

  19. #19
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: I have a good macro to delete duplicates, but I want it to keep last one intact

    Cheers watersev. Thank you!

+ 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