+ Reply to Thread
Results 1 to 22 of 22

Find duplicates in 2 columns and copy/paste to new worksheet

  1. #1
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Cool Find duplicates in 2 columns and copy/paste to new worksheet

    Hi

    Please find attached a workbook of sample data and the results im trying to achieve.

    What I would like is a macro to run rather than currently sorting and deleting manually.

    On the "data" worksheet is the raw data once pasted form another application and I have applied “text to columns” next what I normally do is remove duplicates based on column E then sort based on column J and F then manually remove all non duplicates.

    There must be a duplicate in both J and F, all other data can be deleted.

    If this could be put into a simple macro it would be fantastic as my data is many 1000’s of rows.

    Thanks
    David
    Attached Files Attached Files

  2. #2
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Does this formula highlight what you are trying to delete?

    Sort your data on Column E
    In L1
    Please Login or Register  to view this content.
    Drag/Fill Down

    I have added conditional formatting to make checking easier.

    Note that there are differences in the highlighted rows in Column I.

    Hope this helps
    Attached Files Attached Files
    Last edited by Marcol; 10-23-2010 at 01:29 PM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

  3. #3
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi

    Thanks for the swift reply ,but the answer is no.

    I would like to remove everything apart from the data on the worksheet labeled "report".

    Ideally I would like to run a macro on the raw data in the "worksheet" giving my the data on the "report" worksheet

    Regards
    David

    Regards
    David

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    I'm a bit confused you say
    what I normally do is remove duplicates based on column Ethen sort based on column J and F then manually remove all non duplicates.

    There must be a duplicate in both J and F, all other data can be deleted
    Does this removal include non-duplicates in Column E?

    Got to go for a while, I'll look back later tonight.

  5. #5
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi

    Once the first remove duplicates has been applied to column E, we can inore what happens in that column from then on in.

    The data I will be pasting into the worksheet once working will vary in length of rows also.

    Thanks
    David

  6. #6
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    I'm struggling to match your results.

    This sheet was created using 2007 remove duplicates from your sample data.
    Could you confirm that it agrees with your manual method of clearing?

    It would be a great help in tidying up the next step, if you were to then copy this to another sheet and remove the duplicates in F & J for comparism.

    When the Data is confirmed I will build a VBa solution as you have requested.

    Cheers.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi Marcol

    I think I might be going at this the wrong way round.

    If you look at the new sheet I have attached, with a start of a macro and a full list of data that I use ( this does vary in length from 100 to 50,000 rows )

    If some how the macro could first delete any blank rows until it came across data the inputed

    Please Login or Register  to view this content.
    and was able to paste this down column E first until then end of the data regardless of length.

    then if it inputed

    Please Login or Register  to view this content.
    If the value of that cell was 1, delete row if any other value continue pasting into next cell below in column I etc..untill then end of the data.

    If you copy and paste this formula into all cells in column I at once the spreedsheet hangs as there is so much data in the sumproduct range

    What do you think ?
    Attached Files Attached Files

  8. #8
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Okay, bad timing again!!!

    Got to go soon, at least I'll get back to it with a clear head..........

  9. #9
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Quick check

    Your formula inserted in E2
    Please Login or Register  to view this content.
    This returns P-3-D30 from P-3-D30D12, is this correct?

    Perhaps it should be
    Please Login or Register  to view this content.
    Returning D30D12

    Cheers
    Last edited by Marcol; 10-25-2010 at 11:59 AM.

  10. #10
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi All

    Just had a second thought about this data im trying to sort, rather than deleting lots of data that I don’t want, leaving behind some data that is still not needed and some that is, would it be best to just search for the data I want, using some formula in a macro.

    It going to be quite complicated because the search criteria are different based on a mixture of letter and numbers within the workbook.

    I.e. on a cell containing P-4-D18C71 a match could be any of the following P-4-D18D71 ,P-4-D18E71, P-4-D18C70 or P-4-D18C72.

    But on a cell containing P-1-C18B231 a match could be any of the following P-1-C18A231
    , P-1-C18C231, P-1-C18B221 or P-1-C18B211

    There are a few other scenarios based of the 5th character in a particular cell.
    Is this to tricky ??

  11. #11
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi Marcol

    Ref your post ; Quick check

    Your formula inserted in E2

    Code:
    =MID(D2,1,7)This returns P-3-D30 from P-3-D30D12, is this correct?

    Perhaps it should be

    Code:
    =MID(D2,5,255)Returning D30D12

    I think the first formula will work best, but I can try the second easy enough and compare the data that is left.

    Thanks
    David

  12. #12
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    I'll give it a go. Look back later tonight.

  13. #13
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi Marcol

    The first formula is correct, the second returns a value of 1 ( which we are going to delete rows based on this value ) for some of the data I want to keep.

    Thanks
    David

  14. #14
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

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

    This will take a couple of minutes to run with a file having about 28k rows.

    Check it out for accuracy based on your first set of rules, we can look at more or different rules later

    Have fun!!!........
    Alistair

  15. #15
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi Alistair

    Is this macro running, to the first way of thinking deleting rows based on the value of 1 returned from the sumproduct or running to the rules I thought of based on value in a cell.

    I think its deleting some data I would like to keep at the mo.

    Thanks
    David

  16. #16
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi Alistair

    Could we test using your first thought along with a couple of other idea's.

    Would it be possible to create a macro to do what you first thought about as a start in sorting the data, and actually have it delete the rows, thenI can check to see if the data i want is still there.

    I think this would be a perfect start in reducing the data in size.

    i.e. Sort your data on Column E
    In L1

    Please Login or Register  to view this content.
    If this works maybe create a second macro to do the sumproduct thing and then see what is left after that.

    I dont mind having to run 3 or 4 macros on the data to get results.

    Thanks for all your time.... where do I send the christmas card ?

    Regards
    David

  17. #17
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    It's a starting point based on your first rule, ie based on your first way of thinking.
    I have replaced your SUMPRODUCT with a CONCATENATION and a COUNTIF this seems to run better.

    If you were to list your rules as to what has to be deleted then we could get a better solution.

    Try listing your rules in order of priority, if we can simply remove the obvious duplicates then we can sift the remainder at a more leisurely pace.

    Slainte
    Alistair

    [EDIT]
    Didn't see your last post, silly me.
    This reply still stands
    Last edited by Marcol; 10-25-2010 at 07:51 PM.

  18. #18
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi Marcol

    The macro runs fine, but it deletes some information I wish to keep.

    If you see workbook attached, on sheet1 is the same information as sheet2 but after I have run the macro.

    All the information in bold and red should be kept, also could we keep for now the columns with the letter m in and the two columns with inventory in, this will make it easier to test the data after I run your test macro.

    I think a good start is to have 1 macro to remove exact duplicates as per
    Please Login or Register  to view this content.
    this will remove a lot of data on the real data, if you can some how make the formula and the below run together, this worked when I tied it seperate.


    Please Login or Register  to view this content.
    Then we can test the tricky soration on the data thats left

    What do you think.

  19. #19
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    forgot to attach workbook
    Attached Files Attached Files

  20. #20
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    I'm on a different tack here.

    Try this workbook for an initial sift of your main data.
    The macro removes what appear to be obvious duplicates, to me at least.

    If you do a text to columns on your 28k sample, then paste the result to sheet "TextToColumns" A2 you can test this. Just make sure the columns match this sample,and you retain the header row.

    Then copy sheet "TextToColumns" and run the macro on the copy. This will take a couple of minutes to run
    but it reduces the size from 28k rows to 19k.

    The formulae used are in sheet "TextToColumns" M2 & N2

    The code assumes header rows, so if you try it on a cut-down sheet make sure the headers are in row 1.

    If you could check this out, and if it is okay, then mark-up the next rule that will make a significant difference to the file size.
    Don't try to be over-complicated with this rule if it can be avoided, just be sure it doesn't remove anything you need to retain.

    If we take it step at a time then we will solve this.

    Cheers
    Alistair
    Attached Files Attached Files

  21. #21
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Talking Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi Marcol

    Sorry its been so long, ive been away in another country.

    Many thanks for the work on the forumula.

    Could you try and add into the macro inserting the column I have made yellow on the example attached and add into that column for each row the formula that is there now
    Please Login or Register  to view this content.
    .

    Then change the formula in which will be N2 (once new column is inserted )
    Please Login or Register  to view this content.
    Is the macro removing rows with a count lower than 2 in what was N2.

    This I hope this will remove more data.

    Many thanks
    David
    Attached Files Attached Files

  22. #22
    Registered User
    Join Date
    10-08-2010
    Location
    MK, UK
    MS-Off Ver
    Excel 2003
    Posts
    70

    Re: Find duplicates in 2 columns and copy/paste to new worksheet

    Hi

    I would be very gratefull if anybody can update the macro attached in the pervious post as the coments in the post.

    Thanks
    David

+ 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