+ Reply to Thread
Results 1 to 6 of 6

Merging two files together based on col common to both files

  1. #1
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Merging two files together based on col common to both files

    I am enclosing a file which shoudl help describe what i am trying to do.

    I have two files/sheets of data. Really its files but i show each file on a separte sheet for now to keep things simple. I have a 3rd sheet which shows the "merged" data.

    i want to use VBA to merge or join the two files based on the Lot-id.

    Not sure the best way to approach merging these two files together?

    Any ideas?
    Attached Files Attached Files

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Merging two files together based on col common to both files

    See the attached updated example workbook.

    Copy data sheet 1 as it is to the new merged file. Add a helper column to data sheet 2 and then add INDEX/MATCH formula to the end of the merged file.

    You could record setting it up to make it easily repeatable.

    Regards
    Attached Files Attached Files
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Merging two files together based on col common to both files

    Hi,

    I dont think i can use the index functions to accomplish my goals. I forgot to mention that only a single file will be open at any one time so i dont think i can use the index function. Recall, that each datasheet is actually a single file.

  4. #4
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Merging two files together based on col common to both files

    I have looked online a bit now and i think what i want to do is called "join(merge)" and while i may know a better name for it now i still cant seem to find any vba-code.

    Anyone have any ideas?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,463

    Re: Merging two files together based on col common to both files

    You seem to be making your own contstraints:

    Assume you have a workbook with the code in it, completely independent.
    Open the datasheet1 workbook and copy it to a new merged workbook. Close the original.
    Open the datasheet2 workbook and copy the sheet to the new merged workbook. Close the original.
    Now, with the the necessary sheets in the new merged workbook, add the Helper column to the datasheet2 (worksheet) and add the formulae to datasheet2 (worksheet).

    Convert the formulae to values and you can delete the datasheet2 (worksheet).

    You then have a freestanding merged workbook.

    Probably a bit of a pain to set up but once it's done, it's done.

    Why *do* you only have one workbook open at a time?


    Regards

  6. #6
    Forum Contributor
    Join Date
    12-01-2007
    Location
    USA-North Carolina
    MS-Off Ver
    MS Office 2016
    Posts
    2,662

    Re: Merging two files together based on col common to both files

    hi,

    i was opening up one file at a time because i was combining reading in files from a directory one at a time and then closing them. However, this "other" file i want to merge cant be in the same directory as it is different................than the others. So, your suggestion is starting to look better and better.

+ 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