+ Reply to Thread
Results 1 to 13 of 13

Macro to Split Workbook into separate Workbooks

  1. #1
    Registered User
    Join Date
    05-29-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    15

    Macro to Split Workbook into separate Workbooks

    Hi

    I have a large workbook with many worksheets which are all grouped into pairs - i.e. Sheet1 & Sheet2 go together, Sheet3 & Sheet4 go together; Sheet5 & Sheet6 go together, etc. etc.

    I need a macro to divide this workbook into separate workbooks where each group of worksheets has a separate file of its own and I want to name the new workbooks after the second sheet in each group:

    i.e. A new workbook for Sheet1 & Sheet2 called Sheet2.xls; a new workbook for Sheet3 & Sheet4 called Sheet4.xls; a new workbook for Sheet5 & Sheet6 called Sheet6.xls; etc. etc. etc.

    Appreciate any help I can get on this.
    Ta
    John
    Last edited by jmurray; 07-13-2009 at 06:53 AM.

  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: Macro to Split Workbook into separate Workbooks

    The two sheets are in order and together?
    There are an even number of sheets?
    The original workbook is to be preserved?
    Last edited by JBeaucaire; 07-07-2009 at 07:48 AM.
    _________________
    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 JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to Split Workbook into separate Workbooks

    Give this a try:
    Please Login or Register  to view this content.
    Be sure to set your strPath properly, including that closing "\".

  4. #4
    Registered User
    Join Date
    05-29-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Macro to Split Workbook into separate Workbooks

    Hi

    Thanks for reply. Unfortunately, I get a message saying that "Run-time error 9: Subscript out of Range" - and when i click debug it takes me to the line below:

    Sheets(Array("Sheet" & i, "Sheet" & i + 1)).Copy

    Any thoughts?

    Thanks
    John

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

    Re: Macro to Split Workbook into separate Workbooks

    Can you attach a dummy workbook.
    Hope that helps.

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

    Free DataBaseForm example

  6. #6
    Registered User
    Join Date
    05-29-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Macro to Split Workbook into separate Workbooks

    Hi Roy

    Have attached dummy workbook as requested - appreciate your help.

    Ta
    John
    Attached Files Attached Files

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

    Re: Macro to Split Workbook into separate Workbooks

    The suggestd code doesn't wok because the array needs to contain the sheet names, yours ar not named Sheet1, etc. This amendment will get the sheet names & build the array
    Please Login or Register  to view this content.
    Last edited by royUK; 07-13-2009 at 06:59 AM.

  8. #8
    Registered User
    Join Date
    05-29-2009
    Location
    London, England
    MS-Off Ver
    Excel 2003
    Posts
    15

    Re: Macro to Split Workbook into separate Workbooks

    Thank you - works perfectly!

  9. #9
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Macro to Split Workbook into separate Workbooks

    Please Login or Register  to view this content.
    That's great, Roy!

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

    Re: Macro to Split Workbook into separate Workbooks

    Thanks both

    jmurray please mark this thread solved

  11. #11
    Registered User
    Join Date
    06-16-2009
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro to Split Workbook into separate Workbooks

    Hi to all,

    I want the same thing for my file--split workbook into separate sheets. but with some additional "features".
    What i want to achieve is to divide, thru macro/VB, the entries in my main file into several files, say by 50.
    I attached files for reference. Whereas, the Dummy.xls is the main file and Book1 & Book2 are the desired output.

    Have a nice day

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

    Re: Macro to Split Workbook into separate Workbooks

    chenelas
    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

  13. #13
    Registered User
    Join Date
    06-16-2009
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    4

    Re: Macro to Split Workbook into separate Workbooks

    oppss!
    im so sorry.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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