+ Reply to Thread
Results 1 to 5 of 5

Match cells on two sheets, copy columns to sheet 3

  1. #1
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Match cells on two sheets, copy columns to sheet 3

    Hello everyone,

    I attached an example. In this example I have 3 sheets.
    The first 2 sheets contain "data". The last sheet contains an example of what I would like to have in the end.

    What I would like to do is compare the first 2 sheets with the "Numbers" column. This column doesn't necessarily has to be in the same column.
    If the numbers from sheet 2 are found on sheet 1, I want to copy specific data to the third sheet, which is normally empty.
    In this case column B from sheet 1 and column J from sheet 2.

    Thanks in advance.

    Kind regards,

    Marco
    Attached Files Attached Files

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Match cells on two sheets, copy columns to sheet 3

    Hello Marco,

    The attached workbook has the macro below attached to a button on "Blad3" named "Show Matching Invoices". The macro uses the column headers in row 1 to find the invoice numbers and data. These same headers have to present on the other worksheets that will be searched.

    The worksheet names "Blad1" and "Blad2" are hard coded into the macro. If you change these sheet names then you will need to change them in the macro. The macro creates an array that hold the invoice number and each data element. Only the rows in the array that contain the invoice number and the 2 data elements are copied to the table on "Blad3".

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,587

    Re: Match cells on two sheets, copy columns to sheet 3

    An alternative way with formula.

    In B2 use

    Please Login or Register  to view this content.
    In C2 use

    Please Login or Register  to view this content.
    Formulas can be dragged down.

  4. #4
    Forum Contributor Marco-Kun's Avatar
    Join Date
    04-14-2009
    Location
    Holland
    MS-Off Ver
    Dutch:2007
    Posts
    298

    Re: Match cells on two sheets, copy columns to sheet 3

    @Leith
    Thanks a lot for this solution! It works great!
    I only have one thing though. Perhaps I wasn't too clear, but it doesn't matter whether or not one of the data fields is empty, like you put in your example.
    It still needs to be copied. If there is a matching invoice number, the data, whether or not present, should be copied to Blad3.

    So on Blad3, one row could look like this, with Data2 missing. The only thing needed is a matching "Number". On the original file cells should not be empty, if so, there is something wrong :P
    But just in case, it should copy anyway.

    Please Login or Register  to view this content.
    @kvsrinivasamurthy
    I'm not really sure what your formula has to do since I cannot get them to work. I translated them to Dutch but I still get an error.
    If I read the formula correctly I think they are matching the numbers in column A from Blad3 with the numbers on Blad1 and Blad2, depending one which formula you read.

    Normally Blad3 would be empty and the numbers on Blad1 and Blad2 should be compared. If there are matches, the found numbers plus the data on the same rows should be copied to Blad3.
    Blad3 in the file in my first post is how it should look like in the end.

    If that's exactly what your formula should do, forget what I said.

    Kind regards,

    Marco

  5. #5
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Match cells on two sheets, copy columns to sheet 3

    Hello Marco,

    Here is the updated macro. This will allow you to add as many data columns as like. The table on "Blad3" uses row 1 for the column headers. Column 1 should only be for "Invoices" header. Columns "B" onward should be the "Data" headers. This macro assumes that only one data header exists on a worksheet. If there is more one occurrence then the last value of the data header is used.

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

+ 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