+ Reply to Thread
Results 1 to 13 of 13

macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

  1. #1
    Registered User
    Join Date
    11-02-2012
    Location
    banglore
    MS-Off Ver
    Excel 2010
    Posts
    11

    macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    I looking for a fast macro dat will compare two excel sheets(containing large amount of data) row wise..here i want to take one row from first excel sheet and compare with all rows in another excel sheet.if any of the row from first sheet completely matches with any of the rows in second excel sheet then its ok ,but if doesnt match then copy dat row to 3rd sheet...

    for example
    Sheet 1

    column1 column2
    aa bb
    dd dd

    Sheet 2

    column1 column2
    e e
    aa bb

    Sheet 3

    column1 column2
    dd dd


    I tried wid the following code:

    Please Login or Register  to view this content.



    its working as required but got stucked for long data.

    Then got an idea to use varient for faster comparison.

    Now clueless how to go ahead...can anyone help me in this ?

    Moderator's Edit: Use code tags when posting code. To do so, select your code and click on the # icon above. I have done it for you this time.
    Last edited by arlu1201; 11-05-2012 at 07:29 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    Is there any unique column which can be used to compare both sheets?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Registered User
    Join Date
    11-02-2012
    Location
    banglore
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    No...every row is itself a unique record

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    So each column needs to be checked with each column in a row in the other sheet? How many columns are there?

    Even if there is a mismatch in one column, it should be copied to the next sheet?

  5. #5
    Registered User
    Join Date
    11-02-2012
    Location
    banglore
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    its not about column comparison....its row comparison....if a single value is found changed in a row..it should be copied.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    Yes, but to compare each row, we have to move from one column to the other, right?

    For e.g. compare sheet1 A2 with Sheet2 A2, then move to Sheet1 A3 and compare with Sheet2 A3, etc.

    Do you have a sample file that you can upload?

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.

  7. #7
    Registered User
    Join Date
    11-02-2012
    Location
    banglore
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    Please find the attachment for requirement analysis
    Attached Files Attached Files

  8. #8
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    maybe so
    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    11-02-2012
    Location
    banglore
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    Thnx nilem....macro is working as required....
    but if i increased the data lets say...upto 1500 rows ,its getting slow....

  10. #10
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    yes, the WorksheetFunction in a loop is not a good idea
    try this
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    11-02-2012
    Location
    banglore
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    Thnx nilem...working fine for us....

    one more help dear......
    if there is any way that a macro can return no of difference count (basically no of records in sheet 3) to java from where I m calling macro.

  12. #12
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    Sorry, did not understand your question

  13. #13
    Registered User
    Join Date
    11-02-2012
    Location
    banglore
    MS-Off Ver
    Excel 2010
    Posts
    11

    Re: macro to compare 2 sheets row wise and copy unmatched data to 3rd sheet

    hey....wat i m doing is ...i m writtig data to excel through java..then calling the macro thru java only
    Now wat i want is like ---no of differences in that are writing in sheet3 ..dat count i want to get in java...to show in java console dat " --- records missing"

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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