+ Reply to Thread
Results 1 to 16 of 16

Compare and Copy unique data between 2 workbooks

  1. #1
    Registered User
    Join Date
    09-18-2012
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    14

    Compare and Copy unique data between 2 workbooks

    Hi Experts,

    I started working on a macro that needs to compare and copy unique data from selected row between 2 workbooks. The workbooks have identical headers but only one column should be compared *coulmn C (header named: Invoice Number). So, I will have a Master workbook which will be regulary updated (with new invoices), and other workbooks from where the data will copied. A comparison should be made between master.xlsx and new.xlsx, and if the invoice number is not in the Master.xlsx, than the entire row should be copied from the new.xlsx workbook (sheet1 both).

    I should put a Button on the Master slide, and when clicking it, the data should be compared and transferred.
    Attached I am sending you the both workbooks.

    Any ideas? I would really appreciate your help.

    Regards,
    Pucval
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    09-18-2012
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Compare and Copy unique data between 2 workbooks

    Just to add...

    I am currently using this code, but I want to make it other way around....
    This only selects and copies all rows, and I need to filter only the unique ones. I don't know what is wrong ///

    Any help?

    Here is the code that I am using:

    Please Login or Register  to view this content.

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

    Re: Compare and Copy unique data between 2 workbooks

    Try this code -
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

    The code will prompt you to open the "new" file and then it will do the comparison and copy paste of data.
    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]

  4. #4
    Forum Contributor stojko89's Avatar
    Join Date
    05-18-2009
    Location
    Maribor, Slovenia
    MS-Off Ver
    MS Office 365
    Posts
    913

    Re: Compare and Copy unique data between 2 workbooks

    Ok so here is the code.
    I did notice something though
    If you search the column C for the number and it is not found it copyes the entire row from new to master.
    But the codes that are already in the master workbook don't get updated if any other value is changed in this case Bemerkung column is different for some numbers in master then in new.
    Just a thought

    Code:
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor stojko89's Avatar
    Join Date
    05-18-2009
    Location
    Maribor, Slovenia
    MS-Off Ver
    MS Office 365
    Posts
    913

    Re: Compare and Copy unique data between 2 workbooks

    Well my code works when bouth workbooks are opend.
    You insert this code into VBA for master workbook.
    If you want the master workbook to open the new file then you need to add the code at the top after Dim r As Range
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    09-18-2012
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Compare and Copy unique data between 2 workbooks

    Thank you arlu1201! It works great!

    Only one more thing I'd like do add.. When the code imports the rows, they are not imorted as they are numbered, but they are imported randomly. Is is possible to import them as they are in the new.xlsx file?

    For example when I have invoices from another file (latest.xlsx) and import them to the master workbook, I want them to be on the bottom in the master.xlsx file in order to know what is the latest imported data. Is that possible?

    Thanks again,
    Friendly regards,
    Pucval
    Last edited by arlu1201; 09-20-2012 at 08:40 AM. Reason: Do not quote the whole post.

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

    Re: Compare and Copy unique data between 2 workbooks

    What the macro does for you is copy the new data, then sort the data based on column C, then remove the unwanted rows (dups).

    This may be messing up your order.

    Which is the field which shows the latest imported date? Column A or B? I can re-sort the data based on that field.

  8. #8
    Registered User
    Join Date
    09-18-2012
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Compare and Copy unique data between 2 workbooks

    Column B can be
    Last edited by pucval; 09-20-2012 at 09:34 AM.

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

    Re: Compare and Copy unique data between 2 workbooks

    Updated code -
    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    09-18-2012
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Compare and Copy unique data between 2 workbooks

    arlu1201, it doesn't seem to work or I am making something wrong... My idea is only to add the new data from the first empty row and fill with data below. Precisely, if 25 is the first empty row, then add the new records below. The calendar date does not matter from columns A and B.

    I will also need to run additional task connected to this macro. I hope you can give me some help and I can complete my automation process. In the end, I will go through it step by step in order to learn every single code

    So:
    The Column L is reserved for comments (in the header it's: Bemerkung/Beschreibung). The code needs to check if there is any data in every cell from Column L, and if it's TRUE, the entire row should be transferred to Sheet2 (Tabelle2 in my file), and should be deleted from the master slide (Tabelle1). When the data is transferred to Sheet2 (Tabelle2), it should also be transferred to a new workbook (commented.xlsx) as a backup file.

    Note: this can be added as an additional module and I can create one more Control Button to run it.

    Thank you in advance my saver!
    Pucval

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

    Re: Compare and Copy unique data between 2 workbooks

    Regarding
    I will also need to run additional task connected to this macro. I hope you can give me some help and I can complete my automation process. In the end, I will go through it step by step in order to learn every single code
    Its better you create a new thread, since the question is not directly related to this thread.

    Regarding
    arlu1201, it doesn't seem to work or I am making something wrong... My idea is only to add the new data from the first empty row and fill with data below. Precisely, if 25 is the first empty row, then add the new records below. The calendar date does not matter from columns A and B.
    Even after the sorting its not giving you the output you require?

  12. #12
    Registered User
    Join Date
    09-18-2012
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Compare and Copy unique data between 2 workbooks

    I created new thread regarding my first post, thanks..

    Regarding the sorting, no it does not work. It copies the data randomly, I cannot find the right order. Is it possible just to copy the new rows on the bottom of the table, the first empty row?

    Thanks,
    Pucval

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

    Re: Compare and Copy unique data between 2 workbooks

    Regarding the sorting, no it does not work. It copies the data randomly, I cannot find the right order. Is it possible just to copy the new rows on the bottom of the table, the first empty row?
    This is possible, though i would have to change the code.

    However, in the earlier code i gave you, it compares the data between both the files and retains the new data. Then i sort based on column B. Is that still not what you require?

  14. #14
    Registered User
    Join Date
    09-18-2012
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Compare and Copy unique data between 2 workbooks

    But, there is no order when it copies the data. Maybe because the column B is not formated as Date? It is just a simple string..

    If you can change the code with just copying the new data at the first free row below, that would be great!

    Tnx,
    Pucval

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

    Re: Compare and Copy unique data between 2 workbooks

    Try this updated code -
    Please Login or Register  to view this content.

  16. #16
    Registered User
    Join Date
    09-18-2012
    Location
    Germany
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Compare and Copy unique data between 2 workbooks

    Works beautiful! Thank you! Thank you! Thank you!
    We are still left with the other thread http://www.excelforum.com/excel-prog...70#post2940570 ,
    but I can mark this one as SOLVED

    Regards!
    Pucval

+ 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