+ Reply to Thread
Results 1 to 12 of 12

Split workbook into worksheets

  1. #1
    Registered User
    Join Date
    11-21-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Split workbook into worksheets

    Hi,
    I have got an Excel workbook with a few sheets in. I would like to split the workbook so that each separate sheet is transferred to a new workbook using VBA (in other words, split a workbook into many workbooks) and I would like to be able to choose where to save the new workbooks when the macro is running (meaning, open the save as dialogue).

    Please advise me what to do.

    Many thanks.

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Split workbook into worksheets

    Try:
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Split workbook into worksheets

    Do you want to save all the worksheets to the same folder?

    What name should the worksheets have and which format should they be saved in?
    If posting code please use code tags, see here.

  4. #4
    Registered User
    Join Date
    11-21-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Split workbook into worksheets

    thanks, I get a "Run-time error '1004' Application-defined or object-defined error" when I run the macro. Please advise what to do.

    Many thanks in advance.

  5. #5
    Registered User
    Join Date
    11-21-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Split workbook into worksheets

    I want all of them to be saved in a folder which I specify whilst the macro is running (show the save as dialog). The name of the workbook should be the name of sheet which was copied to it. It should me saved in *xlsx format. Please advise what do do.

    Many thanks.

  6. #6
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Split workbook into worksheets

    If I recall correctly if you do

    Please Login or Register  to view this content.
    and do not provide any arguments it copies to a new workbook. you can then assign activeworkbook to a variable and name it, save it, close etc.

    So as was posted prior, loop the worksheets collection in your source workbook and use worksheet.copy (were "worksheet" is the worksheet object) to create a new workbook from each sheet. Then do what you like with them and close them within the loop once complete.

    you can use workbook.saveas to pass it a path and name to save to (can derive from source workbook or a path you determine statically or dynamically).

  7. #7
    Registered User
    Join Date
    11-21-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Split workbook into worksheets

    Can you please show me all the code together as I am fairly new to VBA.

    Many thanks.

  8. #8
    Forum Expert
    Join Date
    10-02-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    1,222

    Re: Split workbook into worksheets

    Quote Originally Posted by Chaverim View Post
    Can you please show me all the code together as I am fairly new to VBA.

    Many thanks.
    Please dont take this the wrong way but I am here to help, not do it for people. It would go a long way if you posted a sample file (or even 2, a before and after), any existing code you may have and elaborated on your requirements (ie: do you want a dialog for each extracted sheet or 1 to decide where they all go, what file type you want to save as: xlsx, xlsm, xlsb, xls, etc., what do you do if a file by that name exists in the destination already?, any other considerations/requirements).

    When I split a workbook into other files I also typically check that the file names are valid names (not containing symbols which arent valid for example). by posting the above you ensure someone like myself doesnt waste their time and your time writing code that doesnt meet your needs.

  9. #9
    Registered User
    Join Date
    11-21-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Split workbook into worksheets

    Thanks for the quick reply. Firstly, I want one dialog for all the sheets. Secondly, I dont mean this in a bad way either, but if you had looked above at a previous thread that i wrote, i said that i wanted it in xlsx format.

    Many thanks.

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Split workbook into worksheets


  11. #11
    Registered User
    Join Date
    11-21-2017
    Location
    London
    MS-Off Ver
    2016
    Posts
    6

    Re: Split workbook into worksheets

    The code is too long. i have see much shorter codes but you cant choose where to save or save them all in one go. Please advise what to do.

    Many tahnks

  12. #12
    Forum Expert Pepe Le Mokko's Avatar
    Join Date
    05-14-2009
    Location
    Belgium
    MS-Off Ver
    O365 v 2402
    Posts
    13,448

    Re: Split workbook into worksheets

    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).

+ 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 2003 Macro - Split data in two worksheets and place in a individual workbook
    By Isabelle Whyte in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2014, 04:30 AM
  2. Split workbook into multiple workbooks with worksheets
    By itgeltugs in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-21-2014, 11:51 PM
  3. Split data by Criteria into separate worksheets on one workbook
    By TrebleC in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 02-05-2013, 08:39 AM
  4. [SOLVED] Need help linking 2 macros: create workbook and split into many worksheets
    By esmithqg in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-13-2012, 06:27 PM
  5. [SOLVED] Split data into different worksheets in a new workbook.
    By fdotlix in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-31-2012, 07:01 PM
  6. [SOLVED] Split Macro modification to Split into new Workbooks instead of sheets within one workbook
    By DLSmith in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-13-2012, 08:11 PM
  7. Replies: 0
    Last Post: 09-19-2005, 03:05 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