+ Reply to Thread
Results 1 to 8 of 8

Combining Sheets from 5 Workbooks into 1 Sheet

  1. #1
    Registered User
    Join Date
    01-11-2010
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    38

    Combining Sheets from 5 Workbooks into 1 Sheet

    Hello,

    I am trying to combine data from 5 different workbooks into one sheet. They all have the same column headers and the same types of data in each column. For simplicity sake, assume that the workbooks are called Book1, Book2, Book3, etc. and are located on the desktop. I am really running into issues when it is copying the data over and having it automatically detect the last row of data EACH time so it knows where to paste the new data. I have attached 3 workbooks with simple data, so you can see exactly what i'm trying to do. Any help would be much appreciated. Thank you!
    Attached Files Attached Files

  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: Combining Sheets from 5 Workbooks into 1 Sheet

    My basic macro for this task is on this page:

    Merge Multiple Workbooks Into one Sheet (stacked)

    You should only have to tweak the fPath location, and possibly the filter used in the fName = Dir() section, then try it. It might work for you as is.
    _________________
    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
    01-11-2010
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Combining Sheets from 5 Workbooks into 1 Sheet

    So I went in and tried to use what you had posted by only changing what you told me to change. For some reason, the debugger comes on and tells me that I cannot have Loop with Do. See code:

    Please Login or Register  to view this content.
    I see a Do, so I do not know why that is happening. Also, I put this in for fName. Is it correct? Thanks again.
    Please Login or Register  to view this content.

  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: Combining Sheets from 5 Workbooks into 1 Sheet

    No, your fName would probably be:

    Please Login or Register  to view this content.
    ...notice the wildcard in there? That will cause it to pick up each of the filenames one at a time as it Loops.

    I fixed a typo, not sure how that got in there when I uploaded, and a missing End If, so grab the code again.

  5. #5
    Registered User
    Join Date
    01-11-2010
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Combining Sheets from 5 Workbooks into 1 Sheet

    Sorry to keep bothering you, but now I am getting a "subscript out of range" error. I changed the name of the file to pull in .xlsx because I am using 2007. Below is my code. Any thoughts? Thanks again.

    Please Login or Register  to view this content.

  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: Combining Sheets from 5 Workbooks into 1 Sheet

    When reporting an error, always click on DEBUG and let the VBEditor show you the line that's a problem. Then hover your mouse over every variable in that code line and note what the values in those variables are at the moment of error. That may tell you right away what the problem is and perhaps you'll know right away what to fix in the macro or the data/files. If not, at least you have all the information to post here.

  7. #7
    Registered User
    Join Date
    01-11-2010
    Location
    North Carolina
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Combining Sheets from 5 Workbooks into 1 Sheet

    When I put the cursor over the line:

    Please Login or Register  to view this content.
    it tells me that name="". The error message reads: Run Time Error 91: Object Variable or With block variable not set". Thanks for your help.

  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: Combining Sheets from 5 Workbooks into 1 Sheet

    Then your fPath has an error (spelling? hidden spaces? File system is slightly different than you realize) and/or the fName = Dir("Book*.xlsx") is finding no files that match that filter in the fPath denoted.

    I just ran it on my system again, the fPath for me is "C:\2010\" and the fPath = Dir("Book*.xls") and it found the 3 files I put there. So the syntax is right, you're looking for the disconnect between the two parameters and your actual environment.

+ 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