+ Reply to Thread
Results 1 to 19 of 19

Create Multiple Sheets from master sheet

  1. #1
    Registered User
    Join Date
    02-24-2011
    Location
    Brighton, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Smile Create Multiple Sheets from master sheet

    Hi I'm sure this can be done but I cannot for the life of me work it out.

    In a nutshell I want to copy (create) multiple workbooks and name them based on the list of filenames in Sheet1.

    I am using Jerry Beaucaire's excellent FillOutTemplate http://www.excelforum.com/excel-prog...dashboard.html macro.

    The code is working i.e. it is creating the workbooks, all named well and information inputted but I cannot get the code to include extra sheets (it will only copy the one sheet). How can I manipulate the code so that I can also add multiple sheets that appear in the original 'master' workbook? n.b I do not need this to be touched by the code that inserts the data.

    Please Login or Register  to view this content.
    Can this be done?

    Thanks in advance for your help. :-)

    Neil
    Last edited by neilshaw; 05-10-2011 at 05:30 PM. Reason: I have additional information that will assist the resolution of this query

  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: Create Multiple Sheets from master sheet

    Perhaps add this dim at the top:
    Please Login or Register  to view this content.

    Then this before you save the workbook:
    Please Login or Register  to view this content.
    Notice the array? Just edit those strings, add more, delete them, until you have a list of the sheets you want to add.


    End result like:
    Please Login or Register  to view this content.
    _________________
    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
    02-24-2011
    Location
    Brighton, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Create Multiple Sheets from master sheet

    Jerry, the man himself! Thanks so much for the reply, it was looking good until I got a runtime error '9' - Subscript out of range.

    it then highlighted the following row
    Please Login or Register  to view this content.
    Just to clarify, my master sheet currently now has sheets called:-

    1.Data
    2.Template
    3.QRF
    4.Renewal

    Once the batch has been run, I expect to see numbers 2-4 from the above list in each of the 'spawned' sheets.

    Any clues?

  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: Create Multiple Sheets from master sheet

    Runtime Error 9 usually means an object by name cannot be found. Check your sheet names...any hidden spaces in there? Make sure the sheets are named exactly right.

    If not, post up your sample files with the macro in it already and I'll take a look.

  5. #5
    Registered User
    Join Date
    02-24-2011
    Location
    Brighton, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Create Multiple Sheets from master sheet

    I seem to have gotten around that error but now I have a 1004 error, the attachment is on this thread

    http://www.excelforum.com/excel-prog...-workbook.html

    Thanks Jerry

    Neil
    Last edited by neilshaw; 05-07-2011 at 06:14 PM.

  6. #6
    Registered User
    Join Date
    02-24-2011
    Location
    Brighton, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Create Multiple Workbooks with multiple worksheets from master workbook

    Following on from http://www.excelforum.com/excel-prog...ml#post2521369

    I am experiencing a 1004 error and not sure why.

    Any ideas?
    Attached Files Attached Files
    Last edited by neilshaw; 05-07-2011 at 08:08 PM.

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Create Multiple Workbooks with multiple worksheets from master workbook

    Hi,

    Because you are trying to name the second new sheet you add with the same name (Input) as the first sheet you added. The names need to be unique and hence column C on the Data sheet which you are using to generate the names should contain unique values.

    Regards
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Create Multiple Workbooks with multiple worksheets from master workbook

    Feeling of deja vu?

    With this version of your code, when you create your new workbooks, you copy additional worksheets. The last one to be copied is Renewal. This is the active sheet in the active workbook. So, when you say:

    Please Login or Register  to view this content.

    Range("B3") refers to the Renewal sheet and cell B3 has nothing in it.

    Therefore, the save as fails (1004) because the filename is blank.


    Regards
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  9. #9
    Registered User
    Join Date
    02-24-2011
    Location
    Brighton, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Create Multiple Workbooks with multiple worksheets from master workbook

    But the code copies the original sheet, not the previous sheet that was created? Why would the code be set up to copy the previous sheet when it could just as easily do exactly what it did the first time but for the next row? The way I can prove that it works is if you use the following code:-
    Please Login or Register  to view this content.
    Now there you go, three new workbooks, all worksheets named with 'INPUT' as the sheet name. Onto the problem I have, I now want to be able to include any of the sheets (insert some to test it) that are in the 'master' spreadsheet. At the moment, it will only copy the 'Template' sheet, but this is not enough, eventually I want to be able to have up to 15 worksheets copied into each newly spawned workbook.

    Any ideas?

  10. #10
    Registered User
    Join Date
    02-24-2011
    Location
    Brighton, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Create Multiple Workbooks with multiple worksheets from master workbook

    Oh and TMShucks, just to explain the duplication as it's not actually how it looks. I realised that the spreadsheet that I attached to the previous thread was the one that I had working fine before Jerry's code was inserted, my mistake. Which makes me wonder whether you actually ran the code since this spreadsheet works fine (sorry but it had to be said). Anyway that's an aside, due to the forum's limitations I was unable to add or edit an attachment and I could not delete the post; hence the new thread. Apologies for not addressing this sooner.

  11. #11
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Create Multiple Workbooks with multiple worksheets from master workbook

    Not run the code? I'm hurt. I ran the code you provided in the workbook you uploaded. You wasted your time and mine in a fruitless endeavour. The original code fails when you create the sheets in the source workbook. I suspect the new code will do the same. The original code worked fine if separate workbooks are created. The new code fails, as I have explained, because you are copying additional sheets ... and the last one you copy remains the active sheet.

    Your best bet is to define a variable and save the file name / scheme number while the Input sheet is active and then use the variable rather than cell B3 when you try to save the workbook.

    Please Login or Register  to view this content.

    Still think I haven't run the code? Had to be said! ;-)

    Regards

  12. #12
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Create Multiple Workbooks with multiple worksheets from master workbook

    Hi neilshaw

    Wow
    (sorry but it had to be said)
    I should think TMShucks was offering his/her input. Wow.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  13. #13
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Create Multiple Workbooks with multiple worksheets from master workbook

    @jaslake: ... *his* input. And it wasn't from a casual observation of the code, it was from testing it and debugging it ... which I'm guessing the OP isn't actually doing.

    Regards

  14. #14
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Create Multiple Workbooks with multiple worksheets from master workbook

    @TMShucks
    I follow your (in this case HIS) work...I know what you do. The comments of the OP were offensive to me.

  15. #15
    Registered User
    Join Date
    02-24-2011
    Location
    Brighton, England
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Create Multiple Workbooks with multiple worksheets from master workbook

    fantastic, thank you @TMShucks it is now working. There's still a bunch of things I can't understand about what just happened up there and again I will offer my apologies for posting the wrong attachment but @jaslake offensive? hardly.

  16. #16
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Create Multiple Sheets from master sheet

    neilshaw

    Don't start new threads, continue with the original until the problem is solved.

    The Forum "limitations" do not stop you from adding a reply with an explanation that the previous attachment was wrong. I too would take ogffense if someone accused me of not running the code, and anyway it's often not necessary to run the code to see errors
    Last edited by royUK; 05-08-2011 at 02:16 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  17. #17
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Create Multiple Sheets from master sheet

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  18. #18
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,425

    Re: Create Multiple Sheets from master sheet

    @jaslake; @RoyUK: thanks for your comments.

    @neilshaw: you should bear in mind that the people answering the questions do so voluntarily and you will not endear yourself to them by making accusations because you don't understand or like the response given. If it needs any clarification, I *was" offended by the suggestion that I had not run the code but more so by the comment "it had to be said" ... it truly didn't.

    It's probably worth noting that neither of the code solutions you have posted will *ever* work if the option to create the new worksheets in the existing workbook is chosen ... you may as well not ask the question.

    Regards

  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: Create Multiple Sheets from master sheet

    Quote Originally Posted by TMShucks View Post
    It's probably worth noting that neither of the code solutions you have posted will *ever* work if the option to create the new worksheets in the existing workbook is chosen ... you may as well not ask the question.

    Which is why I added the "extra sheets" code into the MakeBooks = True section. If you aren't making separate books, then there's no need at all to duplicate the other sheets, they are already in the workbook and you're just adding more filled out templates.

    To both Neil and TMShucks, although the "it had to be said" comment adds an apparent disrespectful tone to the post(s), it is also possible to read the same posts with the comment as "not disrespectful". It truly is.

    In truth, I have done exactly what Neil wondered out loud to you...I've many times posted on a complex macro purely from a visual analysis... and been right in my assertions. I've also been wrong. In neither instance was I being disrespectful by not running the code.

    Go team!

    ==========

    Neil, if that takes care of your need, please click EDIT in your original post, click GO ADVANCED and set the PREFIX box to 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