+ Reply to Thread
Results 1 to 7 of 7

Merge 2 sheets with common ID column

  1. #1
    Registered User
    Join Date
    08-17-2006
    Posts
    14

    Merge 2 sheets with common ID column

    Hello!

    I need a MACRO that will compare 2 (or more?) sheets from the same work book. Each sheet has a common ID (column A). Other than that, all columns are different with different data. What I need to to do is is combine (merge) all columns from different sheets with the same ID. The problem that one both of the following could be true:

    1) The IDs may NOT be in the SAME ORDER from sheet to sheet.
    2) Some IDs that are on one sheet may not be on the other sheet (or visa-versa).

    An example of what I need is:

    Sheet1 data

    A B
    ID Desc
    111111 This is description 1
    222222 This is description 2
    333333 This is description 3

    Sheet2 data

    A B
    ID Price
    222222 $5.00
    111111 $7.32
    333333 size:CW - $12.50;size:SW - $11.25;

    Sheet3 (combined/merged data)

    A B C
    ID Desc Price
    111111 This is description 1 $7.32
    222222 This is description 2 $5.00
    333333 This is description 3 size:CW - $12.50;size:SW - $11.25;

    Thank you !

  2. #2
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Merge 2 sheets with common ID column

    Hi imimin

    See if the attached helps.
    You will need to create a column of all ID's in Column A of sheet3 and then delete duplicates
    Then look at the VLookup formulas. I hope you don't have multiple ID's the same on a single sheet.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Merge 2 sheets with common ID column

    1 copy column of ids sheet 1 to sheet 3
    2 copy column of ids sheet 2 to end of those now on sheet 3
    3 use advanced filter to extract unique ids
    this list can now be used in sheet3 column a(delete the stuff you copied over)
    now use vlookup
    assuming data starts in a2 then in b2 say your widest data finishes in col h
    =IF(ISERROR(VLOOKUP($A2,Sheet1!$A$2:$H$300,COLUMN(B1),FALSE)),VLOOKUP($A2,Sheet2!$A$2:$H$300,COLUMN(B1),FALSE),VLOOKUP($A2,Sheet1!$A$2:$H$300,COLUMN(B1),FALSE))
    drag acros to col h and down
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,937

    Re: Merge 2 sheets with common ID column

    If you have Access, this is an easy resolution. You can import both tables into Access. Join the two tables in a query and where the data matches, Access will create a report to give you the results.

    If you don't have Access, then you may want to consider using MS Query which is included in Excel. It allows you to query the two tables and do the same as Access.

    Since I am not sure which version of Excel you are using, I cannot direct you to the location on the tool bar or ribbon to find MS Query.

    You may want to do a search on MS Query in Google for specific instructions on how to accomplish this.

    Alan
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  5. #5
    Registered User
    Join Date
    08-17-2006
    Posts
    14

    Re: Merge 2 sheets with common ID column

    Quote Originally Posted by MarvinP View Post
    Hi imimin

    See if the attached helps.
    You will need to create a column of all ID's in Column A of sheet3 and then delete duplicates
    Then look at the VLookup formulas. I hope you don't have multiple ID's the same on a single sheet.
    Thanks! I am using Excel 2000, do you mind changing the file to that format?

  6. #6
    Registered User
    Join Date
    08-17-2006
    Posts
    14

    Re: Merge 2 sheets with common ID column

    Quote Originally Posted by alansidman View Post
    If you have Access, this is an easy resolution. You can import both tables into Access. Join the two tables in a query and where the data matches, Access will create a report to give you the results.

    If you don't have Access, then you may want to consider using MS Query which is included in Excel. It allows you to query the two tables and do the same as Access.

    Since I am not sure which version of Excel you are using, I cannot direct you to the location on the tool bar or ribbon to find MS Query.

    You may want to do a search on MS Query in Google for specific instructions on how to accomplish this.

    Alan
    Thanks! For the project I am on, I cannot use Accesss!

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Merge 2 sheets with common ID column

    Try this one.

    You need to update your profile so we can tell which version we are dealing with.
    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