+ Reply to Thread
Results 1 to 17 of 17

VBA to find duplicate value in a string across entire row and delete one duplicate

  1. #1
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    VBA to find duplicate value in a string across entire row and delete one duplicate

    I have a spread sheet where i need a VBA that will look through an entire row of cells that have a string with which if it finds a duplicate value in the 3rd position of two or more strings, one of the cells will be deleted / Clear contents. I have a spread sheet to show the expected result. Can a form control button be added to activate the VBA?
    Last edited by Hillster; 12-09-2019 at 11:09 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    if found 2 duplicate 1 gets cleared?

    but info in the excel says all get cleared... what is it ?
    Please be as complete as possible in your asking so it may save use all the time to rework the solution because you didn't give all the requirements. If you have a layout in mind please work it out first so we can adapt our solution to it. Thanks.
    If you have been helped, maybe you could click the *

  3. #3
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    make a end result sheet in the workbook you uploaded so we see the desired result and make clear rules as information
    thx

  4. #4
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    Hey Joske920, thanks for your reply, I thought about deleting the farthest to the right cell out of the two duplicate valued cells to show the expected result but then realized that would not be good for you guys because the "argument" would no longer exist, so that is why i kept both duplicates specifically in Row 11 and tried to explain in great detail the reasoning and expected end result in the description box... Hope that makes sense and helps?

  5. #5
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    Joske920, If you take just one row and pretend that is the only row on the entire sheet with what I need accomplished, may help. anytime there are two or more strings that have a duplicate value in the 3rd position of each string, which ever cell that contains the duplicate, the one farthest to the right in the row gets deleted / clear contents. Hopefully that sounds more descriptive..?

  6. #6
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    But in the case of row 7 and row 10, all of the strings have duplicates in the 3rd position. In that case, as in my description boxes on the attached worksheet, the entire row will be empty because there are no other strings of data in the row that contain unique values...

  7. #7
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    hi,

    give this a try
    its not very dynamic but it does the job

    Please Login or Register  to view this content.
    bind the button to that macro and check if every thing is what you wanted

    Grtz

  8. #8
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    Thanks Joske920, trying it as we speak... it is definitely taking a while to process but will let you know when it finishes it's process...

  9. #9
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    well i don't know what you else have going on in the excel you use but this takes not even 5 seconds on my machine
    maybe add:

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

  10. #10
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    Joske920...

    So it is very close... I have yellow highlighted cells that the VBA should NOT have deleted for illustration purposes and yellow highlighted the explanation box that
    hopefully clarify's the end result... As you can see in the attached spread sheet after the VBA ran, it worked perfect in removing duplicates (when found from the 3rd position),
    the only thing is it deleted BOTH strings, i need it to delete only 1 of the 2 that has the duplicate so what we are left with are two strings which both have unique
    values in them... The sheet is now in the state you asked for at the beginning of this thread. (an example of what the finished result should look like) So the cells
    highlighted in yellow should not have been deleted...

  11. #11
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    Joske920,

    Before the VBA runs, there are alot of rows with three stings in them, when the VBA finishes, only two should remain and both of those remaining should be unique to each other... I think you asked the question prior, if 2 have duplicates and only 1 gets deleted....which one does VBA choose to delete from the row? Answer: always the duplicate farthest to the right side of the spread sheet>>

  12. #12
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    ok

    then put a ' infront: ActiveSheet.Cells(currentRow, i) = vbNullString

    run it again and see if thats it

  13. #13
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    Please Login or Register  to view this content.
    ....? copy paste, all of this? and where do I paste it exactly? i know nothing about VBA... Ugh!

  14. #14
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    Hi,
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    All rows with duplicates are deleting perfectly... so technically "SOLVED"... I have to do a count with a regular formula (which i can handle that myself) but the rows that have just one string in them remained after I just ran that last VBA and after pasting the ' in front of that code you advised.... Must be the first 5 rows (5 thru 10) are left with just one string because the VBA was only looking for strings with duplicates in the 3rd position and deleting only one of the duplicate strings... so i guess it makes sense that the VBA would not check to see if any given row had only 1 string to begin with. I can try to figure something out to delete the entire row if only 1 string is found, as i need to calculate rows with 2 strings that are unique values... but thank you so much for your professional and fast assistance!! Awesome work!! I very much appreciate your help!!

  16. #16
    Valued Forum Contributor
    Join Date
    09-30-2018
    Location
    Vlaams Brabant Belgium
    MS-Off Ver
    365
    Posts
    456

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    Hi,

    Please Login or Register  to view this content.
    That should do it.

  17. #17
    Forum Contributor
    Join Date
    09-09-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    176

    Re: VBA to find duplicate value in a string across entire row and delete one duplicate

    Joske920. Perfect, works like a champ! Thank you very much! awesome work...

+ 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. Macros to delete entire duplicate row for duplicate values
    By cutelebel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-19-2014, 12:09 PM
  2. [SOLVED] Delete entire row if duplicate
    By christopherL in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-11-2013, 10:49 AM
  3. Replies: 3
    Last Post: 10-21-2013, 07:33 PM
  4. [SOLVED] Find dupicates in column, and delete entire row(s) containing duplicate(s)
    By staggers47 in forum Excel Programming / VBA / Macros
    Replies: 19
    Last Post: 12-31-2012, 01:28 PM
  5. [SOLVED] Delete entire row if value in the column A is duplicate.
    By swapnilj1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2012, 07:40 AM
  6. Delete the entire row after find any duplicate
    By shyampanda in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-31-2011, 08:14 AM
  7. Replies: 1
    Last Post: 05-11-2011, 07:11 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