+ Reply to Thread
Results 1 to 26 of 26

Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

  1. #1
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Hi,

    I have an very big Excel file that has exactly same columns but different many rows. I need help with an VBA-script to compare each entire row in sheet1 with sheet2 If it dont finds an pair I want it to write the row in sheet3. Its very important that the script starts in row 1 in sheet1 and then loop true whole Range in sheet2 to check If it fond an pair or not. If it cant find an match then I want it to write that row in sheet3.

    So:

    Take first row in Sheet1 save it in temp (or something) then loop in Sheet2 and search for the entire row it picked up earliyer - if it dont finds an match then write the entire row in Sheet3.

    Please need all help I can get!!

    Using Excel 2010 - VBA script pls

    THANKS!!!

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    It would be almost as fast to do this manually - copy Sheet1 to create Sheet3, copy Sheet2's contents to the bottom of Sheet3, then (optionally sort) use Excel's Remove duplicates function. You could easily record and modify a macro to do it.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Hi,

    Thank you for the answer!
    Im sorry but this will not work becuase if I remove all the dublicates I can not track the rows - Thats why I want them in Sheet3 so I can recognize all the difference and correct them.
    Its also like 8-9 of 10 cols can be the same but not the last/first/middle one and then I want it to write the entire row.

    I think that this is an very hard prob

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Then insert a column of formulas on each sheet that you convert to values before processing:

    ="Sheet1, Row " & ROW()

    ="Sheet2, Row " & ROW()

    and don't use that column for the duplicates determination.

  5. #5
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Let say: It takes the first row (col A-Z) save the row in temp - loop true EACH row in sheet2 and try to match it. If it dont get an match write it in Sheet3 else nothing.

  6. #6
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Really need an VBA script for it - I do this maually so many times

  7. #7
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    I have assumed that your sheets are actually named Sheet1 and Sheet2:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Hmm... I can't get it work? I get Errorcode nr 5.
    Will this script takes the first row (col A-Z) save the row in temp - loop true EACH row in sheet2 and try to match it. If it dont get an match write it in Sheet3 else nothing.

    Quote Originally Posted by Bernie Deitrick View Post
    I have assumed that your sheets are actually named Sheet1 and Sheet2:

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Post a sample workbook.

  10. #10
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    I have now upload an test.
    Sheet1 is old data, sheet2 new data, sheet3 is expected result after we have run the script.
    You can se the rows in sheet2 that are markable bold is the differences.

    Quote Originally Posted by Bernie Deitrick View Post
    Post a sample workbook.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Again, thank you so much for your patienece!!!

  12. #12
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    This version gives you the changed rows, without the original rows for reference. Not sure why you were getting Runtime Error 5. Just click the button.

    TEST.xlsm

  13. #13
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Hi Bernie!!!

    This REALLY WORKS! SO GOOD!!!!!

    I just wonder a few things, I can't get it work if the cols are less then to column "Z" - Get Errorcode: 5. How can I optimize it on fastest way so the script can calculate cols by it selfs and not be hard coded?

    I also found that if I only leave one cell with value in Sheet1 (in the whole row) b4 I make the comparison with Sheet2 it can not find that the row is different from the data in Sheet2.

    Know how to fix this?

    Again, Im really thankful for your help and you have extreme excel skills - I have search for an solution for this problems in days but could not find anything.

    Best regards, M

  14. #14
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Use this code for the variable number of columns. As for the single cell only in a row in sheet1, I get the row from sheet2 as part of the output. Perhaps post a file with exactly what you mean....

    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    04-12-2013
    Location
    Usually at work, in the UK
    MS-Off Ver
    Excel 2010
    Posts
    639

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Ignore,I didn't read the initial problem corectly
    Last edited by Sc0tt1e; 04-08-2014 at 04:52 PM.

  16. #16
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    A sheet object does not have an EOF property, a Value property, or movefirst, movenext, or close methods.

  17. #17
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Thank you so much! it works as you say. This have solve 1 of my 2 problems hehe!
    Im sorry if Im such a pain right now but Im wondering how the script can be remade so It it compare Sheet1 with Sheet2 write differences in Sheet3 AND compare Sheet2 with Sheet1 and write the differences.

    Can maybe solve this manually so I can paste Sheet2 in Sheet1 and conversely or Im thinking wrong right now?

  18. #18
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    That is what my original code did - I just commented out that part to give you what you want. Here it is, fully working.
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    I wonder if the script can be rebuild so it recognize this type of differences? I also wonder if the cell that has the difference can be higlighted?



    Example.xlsm

  20. #20
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    To highlight the differences, you need to have something that will
    1) never change
    2) be unique

    Like an ID number - if that exists, then you can use that to determine which two rows are meant to match.

  21. #21
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Hello Bernie,

    Thanks 4 ur answer! In some other documents I will have unique numbers in col "A". Is it possible then?
    Do you know why the script don't recognize differences like the one I post in the new excel document?

    Thanks!

    Quote Originally Posted by Bernie Deitrick View Post
    To highlight the differences, you need to have something that will
    1) never change
    2) be unique

    Like an ID number - if that exists, then you can use that to determine which two rows are meant to match.

  22. #22
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Try running this code after Sheet3 is created - the file you posted had a lot of repeated data; with unique values in A the code works fine (I think)


    Please Login or Register  to view this content.
    Last edited by Bernie Deitrick; 04-10-2014 at 03:33 PM.

  23. #23
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Hmm... That one doesn't work so well. Its highlighted cells in the row thats miss an difference.
    Can the first script not be rebuild so when it fins the difference it highlight it direct when it place it in sheet3?

    Thank you!

    Quote Originally Posted by Bernie Deitrick View Post
    Try running this code after Sheet3 is created - the file you posted had a lot of repeated data; with unique values in A the code works fine (I think)


    Please Login or Register  to view this content.

  24. #24
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    You stated that unique key values are in column A of each sheet - the macro assumes that those values are the same, and any differences are in the other columns. When Sheet3 is sorted by that column, those values should be together.

    Post an actual workbook that you are using.

  25. #25
    Registered User
    Join Date
    06-18-2012
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    28

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    Hi Bernie,

    Again, thank you so much! I really appreciate it. I attach an example workbook in this message.

    Thank you!TEST2.xlsm

  26. #26
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    5,938

    Re: Compare each row in sheet1 to each row in sheet2 -no pair write in sheet3 - HARD

    TEST2.xlsm

    You aren't keeping up with the code changes.

+ 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. Replies: 8
    Last Post: 12-22-2013, 01:16 PM
  2. [SOLVED] Need micro compare code in sheet2 and sheet3 with code in sheet1
    By jamalmail in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-21-2013, 05:15 PM
  3. Compare 2 cells on sheet1 with 2 cells on sheet2 and copy unmatched rows to sheet3
    By drewship in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2010, 07:56 AM
  4. Excel 2007 : Compare: Sheet1 - Sheet2 into Sheet3
    By vbjohn in forum Excel General
    Replies: 3
    Last Post: 07-17-2009, 03:33 PM
  5. A1 in sheet1 =” =SUM('sheet2:sheet3'!A1)”
    By minrufeng in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2006, 03:10 PM

Tags for this Thread

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