+ Reply to Thread
Results 1 to 20 of 20

2 columns find dublicates and delete them with macro

  1. #1
    Registered User
    Join Date
    04-15-2018
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    7

    2 columns find dublicates and delete them with macro

    HI guys,

    i got 2 columns A and B with big data (each ca. 50 000, many different entries, many same). I tried so many things now "conditional formatting" colouring the doubles red, which works great, but it is so much data my excel freezes when trying to sort them so I can delete them.

    Has someone got a macro for comparing 2 columns, deleting them directly in its original column? (dont want extracted data in column C or sth, cause I must know where it was before - A or B).

    I also tried PowerQuery but can't learn to use it, maybe it is easier than I think? Can't also believe that I cant find a macro for this. Seems to me like a standard procedere?!

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: 2 columns find dublicates and delete them with macro

    .
    If you have a matching value in Col A and Col B, which one do you want deleted ?

  3. #3
    Registered User
    Join Date
    04-15-2018
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    7

    Re: 2 columns find dublicates and delete them with macro

    Both!
    And no changing of columns. I dont want a column C where data of A and B are merged or sth like that

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: 2 columns find dublicates and delete them with macro

    .
    One last question (I think) will the duplicates be on the same row with one another ?

    i.e., A5 & B5 .... A10 & B10

  5. #5
    Registered User
    Join Date
    04-15-2018
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    7

    Re: 2 columns find dublicates and delete them with macro

    No!
    Data is partially too different or not the same. Not easy (impossible) to create same rows with that much data. At least for me.
    Last edited by pollux7; 04-15-2018 at 03:29 PM.

  6. #6
    Registered User
    Join Date
    04-15-2018
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    7

    Re: 2 columns find dublicates and delete them with macro

    I invented a "childrens"-method how to make it.

    - I make 4 columns out of 2. --> AB and again AB
    - Then I color the fonts differently in every column --> blue, red, green, pink
    - Then I mix AB in one column and other AB in second column
    - Then I sort first column alphabtically and the other too.
    - Then I delete in both columns the doubles one after another
    - Then I sort colors again and delete in both columns the "shorter color" and the "longer color"
    Last edited by pollux7; 04-15-2018 at 03:47 PM.

  7. #7
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: 2 columns find dublicates and delete them with macro

    Perhaps something like this could be of help?

    Please Login or Register  to view this content.
    And if you wish to keep your column structure replace
    Please Login or Register  to view this content.
    with
    Please Login or Register  to view this content.
    that will give you only empty cells where the duplicate were.

    Alf

  8. #8
    Registered User
    Join Date
    04-15-2018
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    7

    Re: 2 columns find dublicates and delete them with macro

    Alf
    Hm no, but thanx. This only works if for example Row 5908 in A and B is the same. But after Row 20 here it is not same anymore, pretty much at the beginning. And when I start sorting automatically it is still not synchron.

  9. #9
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: 2 columns find dublicates and delete them with macro

    This only works if for example Row 5908 in A and B is the same
    I'm surprised as this is not what I see, marking duplicates with red like this:

    a_del.jpg

    and using the "cell.Clear"command changes it to

    b_del.jpg

    and using "cell.Delete Shift:=xlUp"

    c_del.jpg

    I think you better upload a small sample of how it should look before and after.

    Alf

  10. #10
    Registered User
    Join Date
    04-15-2018
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    7

    Re: 2 columns find dublicates and delete them with macro

    Yes of course, my fault. I expanded 2 lines to B48000. And of course without marking it red and after that deleting red. I want it to be deleted ad hoc. Without marking it red it still needs a lot of time. But I guess it's the way it has to be.

    Please Login or Register  to view this content.
    Last edited by jeffreybrown; 04-17-2018 at 06:53 PM. Reason: Please use code tags!

  11. #11
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: 2 columns find dublicates and delete them with macro

    .
    pollux7

    Set up only 20 rows of numbers. Say Col A: 1 - 20 ... Col B: 21 - 40

    Then place a few duplicates into Col B and run your macro.

    When I run it here, not all of the duplicates are removed.

    ?????

  12. #12
    Registered User
    Join Date
    04-15-2018
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    7

    Re: 2 columns find dublicates and delete them with macro

    When I run it here, not all of the duplicates are removed.
    Yes, hmmm

  13. #13
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: 2 columns find dublicates and delete them with macro

    What I found when testing my macro setup was that I had to do it in a two step process, first mark all duplicate cells and then clear/delete the marked cells in order to get rid of all duplicates.

    As the number of rows you are checking is rather huge you could probably use autofilter for each column as a stand alone for the second part instead of looping through the range. But then you need to set the same condition on the all duplicate cells in order to know what to filter for.

    And of course without marking it red and after that deleting red. I want it to be deleted ad hoc
    Not sure that is possible i.e. I could not make it work but perhaps another forum member has a better idea.

    Testing your modification of my code gives this result by the way.

    aa_del.jpg

    Alf
    Last edited by Alf; 04-16-2018 at 01:47 AM.

  14. #14
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 2 columns find dublicates and delete them with macro

    Hello pollux7,

    Please refer to your Post # 10, and note that your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window.

    More information about these and other tags can be found here

    (Please do this before posting any further.

    In the meantime, you may want to try;

    In a Standard Module, enter the Code as below;

    Please Login or Register  to view this content.
    Now before you run the Code, ensure you have a valid Backup of your Data in Sheet2.

    Regards.
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  15. #15
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: 2 columns find dublicates and delete them with macro

    .
    Winon ... WOW ! So much code to accomplish a small task. Where did your coding skills go ?



    Here's how to accomplish the goal ....


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

  16. #16
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 2 columns find dublicates and delete them with macro

    @ Logit,

    I won't even apologize for the delayed response!

    First I had to go outside to speak "Sailor" and kick the dog, and sniff some dope to calm down. So sorry you were not the Dog, poor animal!

    My interpretation of the OP's requirement is that there should NOT be two of anything in the Columns combined. Your feeble attempt leaves two 13's and two 15's remaining after your "wonderful", shall we say Coding?

    Oh MY!

  17. #17
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: 2 columns find dublicates and delete them with macro

    .
    "My interpretation"

    There in lies the problem ....

  18. #18
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 2 columns find dublicates and delete them with macro

    @ Logit,

    Hey Buddy,

    Please look at Posts 1 through to 5 again. That explains my interpretation, or what am I missing?

    Why do you not delete no's 13 and 15 as well?

    Just wondering.

    Regards.

  19. #19
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: 2 columns find dublicates and delete them with macro

    @ Logit,

    I forgot to mention that one of each of the following no's should remain, and not be cleared; No's. 1, 5, 8, and 9.

  20. #20
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,009

    Re: 2 columns find dublicates and delete them with macro

    Please look at Posts 1 through to 5 again. That explains my interpretation, or what am I missing?

    Why do you not delete no's 13 and 15 as well?
    Because I'm 'jerking your chain' ... nothing better to end my day with !


    pollux7 : Winon and I have been going at it like this for over a year now. Please don't take this seriously ... goodness knows we dont.


    Winon ... I'm done now. Nice to have stepped on your last nerve. Have a great day ! Til we meet again.

+ 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. vb script to find specific names in columns and delete the other columns
    By mac7988 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 11-11-2015, 09:03 AM
  2. [SOLVED] Change macro to highlight Non Dublicates in 2 columns
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-07-2013, 06:18 AM
  3. [SOLVED] Delete dublicates for each row from several columns
    By sunn1ly in forum Excel General
    Replies: 4
    Last Post: 05-21-2013, 04:33 AM
  4. [SOLVED] Highlight dublicates in one column with macro
    By abjac in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-29-2013, 01:13 PM
  5. Replies: 4
    Last Post: 09-18-2012, 10:54 AM
  6. how to delete dublicates rom selected column
    By katya_p in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-07-2012, 09:50 AM
  7. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 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