+ Reply to Thread
Results 1 to 10 of 10

Combine all work books in a single folder to a master workbook

  1. #1
    Registered User
    Join Date
    11-21-2015
    Location
    Saudi Arabia
    MS-Off Ver
    2010
    Posts
    8

    Combine all work books in a single folder to a master workbook

    Combine all work books in a single folder to a master workbook. The Macro should prompt the user to specify the folder where all the files are located. Furthermore, each workbook should be added on the master workbook in a new worksheet tab of the same name as the copied workbook.

    Here are the specifications:
    I have a Master sheet which I would like combine the workbooks of employee (Emp-0001, Emp-0002 etc.) time sheets all of which are located in a single folder depending on the month of the year. For example all the time sheets for the employees are located in the folder Dec-2014 for December-2014, then Jan-2015 and so on. I want the macro in the master file to prompt the user to specify the location of the files and then add these files as separate worksheets inside the master file. I hope I am making sense.

    I am new at VBA so please bear with me.

    Regards,

  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 all work books in a single folder to a master workbook

    'WORKBOOKS TO SHEETS
    Here's a macro for collecting data from all files in a specific folder. This version copies the sheet in as a whole.The parts of the code that need to be edited are colored to draw your attention.
    Last edited by JBeaucaire; 12-26-2019 at 04:07 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
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Combine all work books in a single folder to a master workbook

    This is designed to move the first sheet of every file in the selected workbook into new Master Workbook.

    Please Login or Register  to view this content.


    This might be better as you do not end up with empty sheets in the workbook.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 11-21-2015 at 08:38 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  4. #4
    Registered User
    Join Date
    11-21-2015
    Location
    Saudi Arabia
    MS-Off Ver
    2010
    Posts
    8

    Re: Combine all work books in a single folder to a master workbook

    Thank you for such a quick reply.

    I tried the second code you sent. I am receiving the following error message:

    Run time error '1004'
    "D:\Projects\Consolidate\employees\Emp-001.xlsm" could not be found

    on this line of code
    Workbooks.Open Filename:=ActiveWorkbook.Path & "\" & strname

  5. #5
    Registered User
    Join Date
    11-21-2015
    Location
    Saudi Arabia
    MS-Off Ver
    2010
    Posts
    8

    Re: Combine all work books in a single folder to a master workbook

    Thank you for such a quick reply.

    I tried the second code you sent. I am receiving the following error message:

    Run time error '1004'
    "D:\Projects\Consolidate\employees\Emp-001.xlsm" could not be found

    on this line of code
    Workbooks.Open Filename:=ActiveWorkbook.Path & "\" & strname

    Regards,

  6. #6
    Registered User
    Join Date
    11-21-2015
    Location
    Saudi Arabia
    MS-Off Ver
    2010
    Posts
    8

    Re: Combine all work books in a single folder to a master workbook

    Thank you for your quick reply
    I tried the second part of your code. Ran it. Absolutely nothing happened. The macro just created a employee imported folder. Did i do anything wrong?
    I changed the paths in red as
    fPath = "D:\Projects\Consolidate\employees\Emp-001.xlsm"

    and all the red extensions as .xlsm

    Regards,

  7. #7
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Combine all work books in a single folder to a master workbook

    Try this:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    11-21-2015
    Location
    Saudi Arabia
    MS-Off Ver
    2010
    Posts
    8

    Re: Combine all work books in a single folder to a master workbook

    I figured it out. You are a genius it works!!!! 5ive stars. Now instead of hard coding the file name is there a way to select the folder instead.
    mehmetcik code does that is there a way combine your code with his option of selecting the folder?

    Regards,

  9. #9
    Registered User
    Join Date
    11-21-2015
    Location
    Saudi Arabia
    MS-Off Ver
    2010
    Posts
    8

    Re: Combine all work books in a single folder to a master workbook

    Unfortunately it generates an error at this line
    Sheets("Sheet1").Move
    Error message subscript is out of range.

    Regards

  10. #10
    Registered User
    Join Date
    11-21-2015
    Location
    Saudi Arabia
    MS-Off Ver
    2010
    Posts
    8

    Re: Combine all work books in a single folder to a master workbook

    Hello! JBeaucaire

    Your code works like magic. Just one thing is there a way to remove the part in which the files are getting transferred to the imported folder? I tried removing that section of the code but it didnt work.
    Regards,

+ 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. [SOLVED] merge column D from all csv files in folder to single master workbook
    By up&down in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-04-2014, 06:31 PM
  2. VBA coding for copying data from multiple work books in a folder
    By aravindkm in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-27-2013, 04:34 PM
  3. Replies: 5
    Last Post: 11-14-2013, 12:58 AM
  4. I have 30+ excel work books in a folder, all those i want save in a lower version
    By mahesh1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-08-2013, 04:00 AM
  5. [SOLVED] Need Macro to copy data from a single sheet from work books in the same directory.
    By bird970 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-21-2012, 06:10 PM
  6. Replies: 0
    Last Post: 12-05-2011, 07:17 PM
  7. How to combine info. off work books...
    By jgomez in forum Excel General
    Replies: 1
    Last Post: 03-23-2011, 02:21 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