+ Reply to Thread
Results 1 to 14 of 14

EXCEL VBA challenge . how to merge workbooks into one

  1. #1
    Registered User
    Join Date
    01-30-2015
    Location
    Europe
    MS-Off Ver
    2010
    Posts
    31

    EXCEL VBA challenge . how to merge workbooks into one

    Gurus,

    i have a excel challenge and i tried asking some gurus here at my work, and No one was able to solve this.

    i need a vba code to put in the workbook named MASTER

    master workbook is located in C:/Myfiles

    now there are multiple workbooks in the same directory and all of these workbooks have same numbers of identical sheets that has same names, same field structure; same column headings, and the same column order .

    now the VBA code should combine all of these workbooks sheets into its related sheet into one workbook

    for example lets say that there are 12 workbooks having 5 sheets sheet1 sheet2 sheet3 sheet4 and supposedly each of these worksheets has 10 rows of data excluding the header row.

    when i merge them with VBA then my merged single workbook file will have sheet1 sheet2 sheet3 sheet4 each of these sheets in the merged file idealy should have 120 rows excluding the header row, becuase we had 12 workbooks.

    the only addition would be that i need one new column added to the end of columns on each of the sheets in merged file that shows the original workbook name for those rows.

    any help is appreciated

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: EXCEL VBA challenge . how to merge workbooks into one

    I'm logging off now but here's some code that you could edit for your task:

    Please Login or Register  to view this content.
    in the meantime you could supply some more information - but it's best if you:

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    01-30-2015
    Location
    Europe
    MS-Off Ver
    2010
    Posts
    31

    Re: EXCEL VBA challenge . how to merge workbooks into one

    MASTER MERGED.xlsbCOMPANYB.xlsbCOMPANYA.xlsb


    thanks for your help.

    here is the attachments. the companyA and companyB files are the workbooks to be merged and MASTER MERGED is the example on how the end result should look like after the merger with VBA is done.

    grateful for your help on this.

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: EXCEL VBA challenge . how to merge workbooks into one

    I'll see what I can do tomorrow!

    And, Thanks for the rep!

  5. #5
    Registered User
    Join Date
    01-30-2015
    Location
    Europe
    MS-Off Ver
    2010
    Posts
    31

    Re: EXCEL VBA challenge . how to merge workbooks into one

    xladept

    thank you very much.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: EXCEL VBA challenge . how to merge workbooks into one

    You're welcome!

    Try this:

    Please Login or Register  to view this content.
    Last edited by xladept; 09-25-2015 at 01:21 AM.

  7. #7
    Registered User
    Join Date
    01-30-2015
    Location
    Europe
    MS-Off Ver
    2010
    Posts
    31

    Re: EXCEL VBA challenge . how to merge workbooks into one

    i got error of Run-time error 9
    subscript out of range in this line
    Please Login or Register  to view this content.
    do i run this code from Master Merged file or from another workbook?

    also what are these colons : you used in your code? i have not seen this sort of VBA programming before.

    i would be grateful if you could get this error fixed.

    thanks.

  8. #8
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: EXCEL VBA challenge . how to merge workbooks into one

    Hi,

    The sample file you sent was named "MASTER MERGED" - you must have that file with that name open since that's where you wanted the code to be.

    The colons allow me to put more than one line of code on a line i.e.

    Please Login or Register  to view this content.
    would, otherwise, need to be written as:

    Please Login or Register  to view this content.
    Here's your file - try running it from this
    Attached Files Attached Files
    Last edited by xladept; 09-25-2015 at 02:55 PM.

  9. #9
    Registered User
    Join Date
    01-30-2015
    Location
    Europe
    MS-Off Ver
    2010
    Posts
    31

    Re: EXCEL VBA challenge . how to merge workbooks into one

    xladept

    thanks very much. i changed the Workbooks("MASTER MERGED") to Workbooks("MASTER MERGED.xlsb") adding the file extension then it worked.

    thanks for clarifying the colon

    i have a follow up question, some people use the _ to move to the next line in VBA.
    then my question is which is most preferable and better to use the underscore or the colon as you used?

  10. #10
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: EXCEL VBA challenge . how to merge workbooks into one

    The colon and the underscore are used differently:

    The underscore is a line continuation while the colon makes a new line in the code

    Glad you got it working - I didn't need the extension on my system

  11. #11
    Registered User
    Join Date
    08-19-2006
    Location
    New York, NY
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: EXCEL VBA challenge . how to merge workbooks into one

    Hi,

    I am trying to follow your example, but I am getting an error when I step through the code at
    Please Login or Register  to view this content.
    The error code is:

    "Run-time error '5:

    Invalid procedure call or argument."

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: EXCEL VBA challenge . how to merge workbooks into one

    Hi Top,

    Did you have:
    Please Login or Register  to view this content.
    somewhere before the
    Please Login or Register  to view this content.
    ?

  13. #13
    Registered User
    Join Date
    08-19-2006
    Location
    New York, NY
    MS-Off Ver
    MS Office 2013
    Posts
    33

    Re: EXCEL VBA challenge . how to merge workbooks into one

    Yes, I have U= DIR(P) in line 3

  14. #14
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: EXCEL VBA challenge . how to merge workbooks into one

    Hi Top,

    Start another thread and give a link to it here then:

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel 2007 : Merge excel workbooks
    By Dutchvillain in forum Excel General
    Replies: 1
    Last Post: 10-25-2010, 03:43 PM
  2. Excel Mail Merge Challenge
    By mimottershaw in forum Excel General
    Replies: 2
    Last Post: 02-24-2008, 11:34 AM
  3. Compare and Merge Workbooks in Excel
    By colin41 in forum Excel General
    Replies: 7
    Last Post: 03-26-2007, 07:21 PM
  4. [SOLVED] How do I merge two different excel workbooks
    By Jesse R. in forum Excel General
    Replies: 2
    Last Post: 08-22-2006, 10:05 AM
  5. [SOLVED] How to merge various workbooks into 1 worksheet in Excel
    By Sharm in forum Excel General
    Replies: 1
    Last Post: 08-22-2005, 04:05 AM
  6. Is it possible to merge workbooks in excel?
    By trm5214 in forum Excel General
    Replies: 3
    Last Post: 05-03-2005, 05:06 PM
  7. merge excel workbooks
    By Theresa in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-06-2005, 03:06 PM

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