+ Reply to Thread
Results 1 to 26 of 26

Delete duplicate rows by cell value

  1. #1
    Registered User
    Join Date
    01-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Delete duplicate rows by cell value

    Hello,

    Please can someone help.

    I have a large database with information and want to delete rows with Duplicates based on cell Values but retain the latest row.

    So for example:

    I want to check if values in Cell A1 & C1 are duplicated in any rows and delete old rows. I will have F1 as my timestamp.

    So if Rows 12, 16 have same values as in A1 & C1 and Row 12 has the last time stamp, I want to delete Row 1 & 16.

    Hope this makes sense and sorry If I have not explained myself clearly.

    Thanks.

  2. #2
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    Hi, how's you VBA knowledge, can you program a little?
    The idea is to translate what you have explained to code and I would suggest that you use a helper column and place a 1 in each row that you want to delete and then when all the data has been checked delete those rows that have a 1 in that column, but then again, you will have to write that macro.
    ---
    Hans
    "IT" Always crosses your path!
    May the (vba) code be with you... if it isn't; start debugging!
    If you like my answer, Click the * below to say thank-you

  3. #3
    Registered User
    Join Date
    01-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Delete duplicate rows by cell value

    Thanks for your reply.

    My VBA knowledge is very minimal.

  4. #4
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    Minimal as in none or some knowledge of VBA?

  5. #5
    Registered User
    Join Date
    01-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Delete duplicate rows by cell value

    Sorry, none.

  6. #6
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    If you attach a file with the layout and some dummy data as you have it, i will write some code for you

  7. #7
    Registered User
    Join Date
    01-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Delete duplicate rows by cell value

    Excel2.jpg


    Am sorry, but for some reason I am unable to attach documents, so I have uploaded this as an image.


    So I want to check if B2, G2 and I2 are the same in any other rows and delete them leaving the last updated row based on the Time Stamp.

    I am hoping to delete rows 2 and 3.

    Thanks for your help!

  8. #8
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    How to attach upload files
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Delete duplicate rows by cell value

    Thank You.

    Attached is the excel sheet.

    Thanks Again.
    Attached Files Attached Files

  10. #10
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    Okay, I'll take a look later today

  11. #11
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    Just to make sure you mention

    I want to check if values in Cell A1 & C1 are duplicated in any rows and delete old rows. I will have F1 as my timestamp.
    But A1 is empty (maybe for privacy) but B and C are the ones I can use too?
    B is the Client ID (or something similar) and B the date
    The timestamps in J (not F are the ones to check.
    Correct?

  12. #12
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    You did not answer my questions but here's my solution based upon my assumptions being correct
    I placed as much comments as I thought necessary to explain the strategy.
    Another thing is you do NOT have to sort the table before processing it will work irrelevant to the sort order
    Let me now , I added some records for this test
    The result will be 4 rows
    Attached Files Attached Files

  13. #13
    Registered User
    Join Date
    01-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Delete duplicate rows by cell value

    Apologies, I missed replying to your queries. Yes, yur assumptions are correct.

    I get a 'Run Time Error 1004'. Application defined or object defined error when I run the script.

    Thanks for your time.

  14. #14
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    Have you debugged the code, can you tell me at what line it happens, the file I attached works, just tested it.
    Are you running it in this file or did you copy the code elsewhere?

  15. #15
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Delete duplicate rows by cell value

    Possibly...
    Please Login or Register  to view this content.

  16. #16
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    I'm still waiting for his answer, when and which line gives the error.

  17. #17
    Registered User
    Join Date
    01-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Delete duplicate rows by cell value

    I get a Run Time error 13 on the file you have attached. When I debug, hope this is correct, by using the F8 key, I get Line 1( Sub test (2)) and lines 14,15,18,19,20,21 highlighted. Sorry, if I am doing anything wrong.

  18. #18
    Registered User
    Join Date
    01-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Delete duplicate rows by cell value

    Quote Originally Posted by dangelor View Post
    Possibly...
    Please Login or Register  to view this content.
    Thanks. Am getting a Run Time Error 1004, Application defined or object defined error.

  19. #19
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    I cannot help you with this file, I hope that he answers.
    My file works fine.

  20. #20
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    I took a alook at the code and my guess is that you get the error once there are no more rows to delete.
    I also got the error using the file two after the first run.
    So you will have to add an extra check that if there is nothing to delete the skip that part.

  21. #21
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    Try this
    Please Login or Register  to view this content.

  22. #22
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    BTW, I checkd but this last macro does not correctly remove duplicate rows.
    The result should be 4 row but it leaves 6 (2 sets still duplicated)
    The data used:
    Please Login or Register  to view this content.



    Please Login or Register  to view this content.
    This is the resulf with my macro:
    Please Login or Register  to view this content.

  23. #23
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Delete duplicate rows by cell value

    Try this and be sure to copy it to a code module, not a sheet code module.
    Please Login or Register  to view this content.

  24. #24
    Registered User
    Join Date
    01-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    17

    Re: Delete duplicate rows by cell value

    Thanks, this works.
    When there are no duplicates though, it comes up with Run Time Error 1004, no cells were found and when i debug, it points to r.SpecialCells line at the bottom.

  25. #25
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Delete duplicate rows by cell value

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

  26. #26
    Forum Expert Keebellah's Avatar
    Join Date
    01-12-2014
    Location
    The Netherlands
    MS-Off Ver
    Office 2021 (Windows)
    Posts
    7,905

    Re: Delete duplicate rows by cell value

    Similar to my suggestion in #21

+ 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] UDF to delete all duplicate rows in a Column but one if cell value = myString, not working
    By capson in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 11-25-2015, 06:13 PM
  2. Replies: 1
    Last Post: 11-23-2015, 03:26 PM
  3. [SOLVED] Delete rows on basis of duplicate & blank cell
    By sanjuss2 in forum Excel General
    Replies: 3
    Last Post: 09-10-2015, 06:38 AM
  4. [SOLVED] VBA macro, move cell contents, duplicate down if additional value, delete empty rows
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-07-2015, 10:46 AM
  5. [SOLVED] Delete rows based on duplicate cell, but leaving first and last duplicate.
    By LadyNicole in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-28-2013, 05:07 AM
  6. Delete duplicate rows, but keep the cell that has the latest date
    By vaznlyfe in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-20-2012, 01:35 PM
  7. Re: Delete rows based on duplicate and cell color
    By Jsin in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2010, 08:38 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