Closed Thread
Results 1 to 10 of 10

Combine multiple workbooks into one single workbook

  1. #1
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,166

    Combine multiple workbooks into one single workbook

    I am trying to combine ~300 workbooks into one single workbook. All 300 workbooks have the exact same header. I tried using the code from thread https://www.excelforum.com/showthread.php?p=696435 but nothing is being copied over. The only difference between my example and the other is I only need to take data from the first sheet in each data workbook. All the workbooks are located in following directory
    Please Login or Register  to view this content.
    The “master file” is located in another directory. The “master file” also has the same header as the data workbooks. Basically, I want to retrieve all data (excluding the header) from the first data workbook and copy to the master file. Then I want to go to the second workbook and retrieve all data from the second data workbook and copy to master file, and so on. The code I am using to combine is as follows:
    Please Login or Register  to view this content.
    Thank you in advance for any assistance.
    Last edited by maacmaac; 02-23-2010 at 09:29 PM.

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine multiple workbooks into one single workbook

    FileSearch doesn't work in Excel 2007, so to have a method that will work in all your Excel versions, try this macro of mine I use for this very task.

    The only additional thing you would need to do is create a folder called "Imported" inside the folder with the files, the macro will import the data and move the files to the imported folder so there's no chance they'll be imported again if you run it a second time.

    OR...delete the two lines of code that say "Optional" and that part will go away.

    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 02-22-2010 at 03:32 AM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,166

    Re: Combine multiple workbooks into one single workbook

    I am running the code line-by-line. It is going through the code fine and copying data from each book and pasting it into the MasterCombine workbook. However, when it gets the last workbook, everything is deleted and it reverts back to the original file with original data. It appears to be crapping out when it gets to command that opens file.
    Please Login or Register  to view this content.
    I can't for the life of me figure out what is wrong. Any help is appreciated. I am trying the code in Excel 2003.

    I have all the data in one path, which is "G:\Excel Tips\Combine Workbooks\WorkbookData\" The files are:
    Book1
    Book2
    Book3
    Book4
    Book5
    MasterCombine (contains code to combine Book 1-5)

    I have another path, which is "G:\Excel Tips\Combine Workbooks\WorkbookData\Import\"
    This folder is empty.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    02-23-2010
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Combine multiple workbooks into one single workbook

    Try the RDBMerge Add-In at the URL:
    http://www.rondebruin.nl/merge.htm

  5. #5
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Combine multiple workbooks into one single workbook

    so is the code supposed to merge all the data from all the workbooks into one workbook, one master sheet or into one folder? Because it would make more sense to have the files merged into one workbook with the individual sheet being renamed based off of the originating workbook title, wouldn't it??

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine multiple workbooks into one single workbook

    I have a macro for that, too.
    Please Login or Register  to view this content.

  7. #7
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,166

    Re: Combine multiple workbooks into one single workbook

    Still can’t figure out what I am doing incorrectly. I have attached a word document that shows the location of the files I want to combine into one single sheet. Also attached is a copy of the desired output and two example data workbooks.

    I am trying to combine the data in different workbooks in to one single sheet. As an example, say I have 5 workbooks I want to consolidate.
    Book1 – contains data for Apples
    Book2 – contains data for Oranges
    Book3 – contains data for Beans
    Book4 – contains data for Pears
    Book5 – contains data for Bananas

    I need to take all the data from all 5 workbooks and put it into one single workbook. Thank you for your patience on this issue but I don’t know if I have the files in the wrong folders or maybe I am not executing the code correctly. Thanks again.
    Attached Files Attached Files

  8. #8
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine multiple workbooks into one single workbook

    Could be several things. I imagine having the MasterCombined in the same directory as the files to import is probably a bad idea. So move it so that it resides elsewhere, maybe inside the IMPORTED directory?

    Here's one last tweak on the macro, they all work for me, so I can't imagine what's going wrong for you. Your uploaded sheet didn't include the macro, so I couldn't see what/where you actually placed the macro...goes in a standard module (Insert > Module).

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

  9. #9
    Valued Forum Contributor
    Join Date
    11-20-2003
    MS-Off Ver
    2010, 2016
    Posts
    1,166

    Re: Combine multiple workbooks into one single workbook

    PERFECTO!!! Thanks so much. It is exactly what I need. Can't tell you how much time this going to save me.

  10. #10
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Combine multiple workbooks into one single workbook

    I'm thinking the MasterCombine being in the same folder may explain why it appeared to be working all the way til the end and then suddenly everything disappeared. Hehe, that would be frustrating.

Closed 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