+ Reply to Thread
Results 1 to 19 of 19

Merging multiple workbooks that contain identical tabs

  1. #1
    Registered User
    Join Date
    03-17-2011
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    11

    Merging multiple workbooks that contain identical tabs

    I have multiple workbooks, all located in the same folder, and I want to merge them into a singular workbook. Each workbook contains 22 worksheets and each workbook have identical worksheet names. Each tab has a header that fills rows 1 through 5 after which the data starts. There is no naming convention for the workbooks as each come from seperate employees who name them what they will, but the template within thet workbooks remains the same.

    I found the following code which is able to bring the workbooks together and recognize when two worksheets share the same name but instead of merging the two worksheets into one it appends a (2),(3), etc. when duplicate worksheet names are detected.

    What I want to be able to do is select which workbooks I want to combine and then have the workbooks combine and have all the tabs that share names combine into a singular tabs.

    If what I am asking is impossible or if I am being anyway unclear in what I am asking please let me know and I will attempt to clarify. I can upload a copy of the workbook I am trying to merge together if that helps.

    here is the code i found previously:

    Please Login or Register  to view this content.
    Thanks in advance!
    Last edited by glurbly; 03-18-2011 at 01:09 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: Merging multiple workbooks that contain identical tabs

    Hi Glurby, welcome to the forum.

    Be sure to read through the Forum Rules so you can use and follow them effectively. For instance, you'll need to EDIT that post above and put code tags around that code you used. (Like shown in my signature)

    ========
    WORKBOOKS W/MULTIPLE SHEETS MERGED INTO SHEETS IN CONSOLIDATION WORKBOOK

    Meanwhile, here's a macro for collecting data from all sheets in all files in a specific folder merging into matching sheets.You will want to edit the fPath variable to your folder, or insert your own method of "selecting a folder".

    You'll also want to edit this one line of code to copy from row6 on....
    Please Login or Register  to view this content.
    Slip that macro into a "master" workbook with all your sheet tabs laid out.
    Last edited by JBeaucaire; 03-17-2011 at 03:14 PM.
    _________________
    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
    Registered User
    Join Date
    03-17-2011
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Merging multiple workbooks that contain identical tabs

    apologies for failing to follow the forum rules earlier I wasn't aware of them.

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

    Re: Merging multiple workbooks that contain identical tabs

    No problem. That macro suggested should work great for this.

  5. #5
    Registered User
    Join Date
    03-17-2011
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Merging multiple workbooks that contain identical tabs

    The Macro didn't have the results I was looking for. The result was a triplicate of the third row in each worksheet of the master workbook and it did not copy all of the rows beneath row 6 in each workbook. It seems to have only copied the 6th row from one of the worksheets and then stops there.

    I would upload a copy of the master so you could see what exactly it looks like but I keep getting an error from excelforum saying database error.

    thanks so much for your help and patience with this problem I'm incredibly new to the world of Macros.

  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: Merging multiple workbooks that contain identical tabs

    the macro expects to be able to look UP column A to spot the last row of data for the LR variable. Is that not the case? Is Col A filled in for the data set all the way down? Sometime people make odd layout design choices like skipping column A.

    Seeing a sample workbook, of course, always a good place to start. Your wb is probably too big. trim it down as a sample, or zip it up first.

  7. #7
    Registered User
    Join Date
    03-17-2011
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Merging multiple workbooks that contain identical tabs

    You were right shrinking down the file did work. Each of the worksheets in each workbook look like this.

    Column A doesn't always have data. Column C (main activity) is the first column guaranteed to have data in it. Sometimes there is data in Columns A and B as well but it depends on which employee I am receiving the workbook from. Is there a way to alter the code to look up column C for the LastRow data while still copying Columns A and B in the process?

    thanks again
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    03-17-2011
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Merging multiple workbooks that contain identical tabs

    I fixed the problem about the rows not copying correctly by altering the code slightly, by making it look up the C column not A.

    But there is one problem still remaining, if one of the worksheets doesn't have any data the last row of the header is copied and put into the master, how can i avoid this?

    I need to be able to because only certain employees fill out each worksheet, one may fill 20 of the possible 22 worksheets while another may only fill one of 22.

    thanks so much.
    Last edited by glurbly; 03-17-2011 at 09:44 PM.

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

    Re: Merging multiple workbooks that contain identical tabs

    Add an "IF" test on that copy line. Change this:
    Please Login or Register  to view this content.
    ...to this:
    Please Login or Register  to view this content.
    Last edited by JBeaucaire; 03-18-2011 at 11:53 AM.

  10. #10
    Registered User
    Join Date
    03-17-2011
    Location
    toronto
    MS-Off Ver
    Excel 2003
    Posts
    11

    Re: Merging multiple workbooks that contain identical tabs

    It works perfectly now.

    Thanks so much for your help, this macro has made life so much easier.

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

    Re: Merging multiple workbooks that contain identical tabs

    If that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  12. #12
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Merging multiple workbooks that contain identical tabs

    The macros that you have attached to this post seems to be exactly what I am needing. One question though, what do I need to change the below to?

    Sheets("Report001").Copy After:=Sheets(Sheets.Count)

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

    Re: Merging multiple workbooks that contain identical tabs

    This macro is designed to "create" new sheets whenever one is needed by copying an already existing sheet called Report001, so for your workbook you would change that to the name of the sheet you want the macro to use.

  14. #14
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Merging multiple workbooks that contain identical tabs

    I have a master workbook created that has three sheets. "Advance", "Datacomm", "Philips". Each workbook that I am bringing in has those same three sheets in them. What would I change the Report001 to?

  15. #15
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Merging multiple workbooks that contain identical tabs

    I have a master workbook that has tabs "Advance", "Datacomm", "Philips" on it. The workbooks that I am wanting to merge over have the same three tabs. I am a little unsure of what I should replace the Report001 with.

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

    Re: Merging multiple workbooks that contain identical tabs

    Sounds like you're using the wrong macro from my site. You should be using PART 4 to bring in data from multiple worksheets into a master workbook where the sheet names match. Use the link in post #2, use the correct macro.

  17. #17
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Merging multiple workbooks that contain identical tabs

    Oh that makes sense now. I am using the consolidatedsheetsfromworkbooks and I am getting a debug error on

    fName = Dir(fPath & "*.xlsx") 'start looping through files one at a time

    My master workbook is called "Master". and i have three tabs that are labeled the same as the ones in the workbooks I am wanting to merge. Any suggestions?

  18. #18
    Registered User
    Join Date
    07-28-2011
    Location
    USA
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: Merging multiple workbooks that contain identical tabs

    Oh that makes sense now. I am using the consolidatedsheetsfromworkbooks and I am getting a debug error on

    fName = Dir(fPath & "*.xlsx") 'start looping through files one at a time

    My master workbook is called "Master". and i have three tabs that are labeled the same as the ones in the workbooks I am wanting to merge. Any suggestions?

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

    Re: Merging multiple workbooks that contain identical tabs

    Start a new thread of your own, post your sample workbook(s) that include your edited versions of my macro in them.

    You can send me an invitation to that thread once it is started. Include a link to it please.

+ 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