+ Reply to Thread
Results 1 to 39 of 39

Regrouping worksheets from several workbooks into a single Workbook

  1. #1
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Regrouping worksheets from several workbooks into a single Workbook

    Hi all,

    I'm using Excel 2010. Is there a fast way (formula or VBA) to regroup worksheets (into a single workbook) from a same workbook that has been distributed to different users?

    Here is a simplified version of the scenario in more detail: I have a Workbook called A and it contains worksheets named 1,2,3,4,....10. I have sent the workbook to 5 different users and each of them have worked on specific worksheets of the Workbook. There's no duplicate work done any user...by that I mean, worksheets 1 to 3 have been attributed to User 1, worksheets 4 to 5 to User 2, and so on.

    Now that each user has returned the workbook with their worksheets filled, I need to regroup all the 10 worksheets into a single workbook.


    Is there a fast way to do this rather than copy and paste each worksheet into a new book?


    cross post: http://www.ozgrid.com/forum/showthread.php?t=178723
    Last edited by zicitron; 05-20-2013 at 05:16 AM. Reason: Update cross posting link

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    The macro can do the copy paste for you.

    I have a question - If workbook A is being sent to User1, he will fill up only sheets 1 to 3. So will the other sheets exist in the file returned by him or will they be deleted? If they exist, will they be blank?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Thank you arlu1201. User 1 will return the workbook with the other sheets still in the workbook. He won't delete them. In fact they won't be "blank" like empty worksheets. They will contain pre-formatted tables but it's just that if the User is not concerned with that worksheet, he will leave it as is. He will fill data only in the worksheets assigned to him.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Ok, the reason i asked you is - when we consolidate all the sheets from all the files, there will be duplicate sheets created which wont be of any use. Hence, i thought that the macro can check if a particular cell like A1 or any other is not populated, then it does not need to consolidate that sheet.

  5. #5
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Yes that would indeed be great if the macro could indeed check certain specific cells in the worksheet and transfer that worksheet into the consolidated workbook if it finds data there. Can you help with the macro or point me somewhere where I can find one that would do the job? I am total newbie as far as VBA codes are concerned!

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    I can help you. Which are the cells which need to be checked? Even one cell will do which you know will always contain data if its the user's sheet.

  7. #7
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Thank you arlu1201 for offering to help!

    The cell D7 in each worksheet is a mandatory cell to be filled. As the worksheets are named "FR, UK, GER....", it would be nice if you could use those names in the VBA code. It would help me to edit it more easily!

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Actually, we do not need to mention the names of the sheets. The macro will loop through all the sheets in all the workbooks required and check if D7 is filled. If yes, copy that sheet to a new workbook, if not, skip it.

    Are all the files stored in one folder?

  9. #9
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Yea arlu1201. They will be stored in the same folder. I guess I will need to rename the workbooks since it was the same workbook that was sent to all the users.

  10. #10
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Hi arlu1201...any updates on the VBA code?

  11. #11
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    You may not need to rename the files. How would you be receiving them? By email and then you would be saving them in one folder?

  12. #12
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Yes exactly.

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    So when you save them, would they be having the filename as workbookname(1) then workbookname(2), etc?

  14. #14
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    The main workbook is called CDM Budget and it has tabs named FR, UK, GER.....
    I am thinking of naming them as CDM Budget FR, CDM Budget UK, .....
    But you set them as workbookname(1), then workbookname(2) in the codes....I will modify accordingly.

  15. #15
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    No no, i do not need to set anything. However you save the files, as long as they are saved in one particular folder, the macro will pick up all the files in that folder and execute the macro.

  16. #16
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    I will provide you the code in sometime. The code will check for D7 be filled up in each sheet of each file. Only those sheets having that cell filled will be consolidated into a new workbook.

  17. #17
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Ok, great! Thanks again for your invaluable help! I really appreciate!

  18. #18
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Hi arlu1201...Is it possible to have the VBA today? I have a deadline to submit my consolidated file by tonight. No pressure from me but just a kind request as to whether it would be possible. In case you are busy and it won't be possible, that's fine! You can send it to me later.

  19. #19
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Try this code -
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  20. #20
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Regrouping worksheets from several workbooks into a single Workbook

    You must have missed the OPs deadline, arlu1201 - posted on Ozgrid about 15 minutes before you replied here.

  21. #21
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Thanks cytop.

    zicitron,

    I'm afraid your post does not comply with Rule 8 of our Forum RULES. Do not crosspost your question on multiple forums without including links here to the other threads on other forums.

    Cross-posting is when you post the same question in other forums on the web. The last thing you want to do is waste people's time working on an issue you have already resolved elsewhere. We prefer that you not cross-post at all, but if you do (and it's unlikely to go unnoticed), you MUST provide a link (copy the url from the address bar in your browser) to the cross-post.

    Expect cross-posted questions without a link to be closed and a message will be posted by the moderator explaining why. We are here to help so help us to help you!

    Read this to understand why we ask you to do this, and then please edit your first post to include links to any and all cross-posts in any other forums (not just this site).

  22. #22
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    I'm sorry arlu1201. I apologize for this. I didn't realise about the cross posting.

  23. #23
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    arlu1201, thank you very much for the codes! I tried it but I get a runtime error 1004 stating that the D:\CT cannot be found! This is the folder where I have all my workbooks stored.

  24. #24
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    update: the problem was that the excel files have been saved as xls versions. I've corrected that in the code and ran it again.
    Now, it stops with "subscript out of range" message. When I click the Debug button, it highlights the following line: "sourceData.Copy after:=Master.Worksheets(Worksheets.Count)". Any idea of what's wrong?

  25. #25
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Hmm, i ran it at my end and i didnt get any errors.

    Are both the workbooks - the New one created by the macro and the source file open?

  26. #26
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    When I run it, it opens a new book but I can't see the source files being opened.

  27. #27
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Did you make any changes to the macro?

  28. #28
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    the only changes i made were the following:
    (1) I changed the path to where my folder resides
    (2) I changed xlsx to xls

    Do I need to save a workbook as "Master" and run the macro from there?

  29. #29
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Right now, I'm doing the transfer manually until I find the solution! :-(

  30. #30
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    You do not need to save the file. Did you put the last "\" after the file path? The code will put that. You do not need to.

  31. #31
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    No, I didn't.

  32. #32
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Works fine at my end using .xls files too. One question - where have you copied the code to? In a blank module?

  33. #33
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Yes in a blank module. I followed your instructions where you mentioned "Insert Module". I pasted the code in that newly created module.

  34. #34
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Can you upload the file you are using after removing the sensitive data? I will try running the macro on your file.

  35. #35
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Ok, I will do so and upload the file soon.

  36. #36
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Hi arlu1201...I did a test again by creating 3 Excel workbook and randomly placed data in cell D7 in some of the worksheets. The workbooks were saved in Excel 97-2003 format (ie:.xls). I stored all the 3 wrokbooks in D:\test
    I ran the VBA code, after modifying it accordingly but again, it gave me a runtime error and when pressing the "Debug" button, it highlights this part "sourceData.Copy after:=Master.Worksheets(Worksheets.Count)" in yellow.
    I am attaching the 3 excel files.
    Book1.xls
    Book2.xls
    Book3.xls

  37. #37
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    When i ran the macro earlier, it had not given me the error. But when i ran it this time with your files i got it.

    Change this line from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  38. #38
    Forum Contributor
    Join Date
    05-09-2013
    Location
    Mauritius
    MS-Off Ver
    Excel 2010
    Posts
    116

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Wow! It works a treat! Thank you a lot arlu1201! I really appreciate your help. You've gone to great length to sort this out. I don't have enough words to thank you!

  39. #39
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Regrouping worksheets from several workbooks into a single Workbook

    Am glad its solved.

+ 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