+ Reply to Thread
Results 1 to 9 of 9

Macro to export each sheet after Master Sheet as separate workbook including Master

  1. #1
    Forum Contributor
    Join Date
    06-03-2004
    Location
    India
    MS-Off Ver
    2013
    Posts
    205

    Macro to export each sheet after Master Sheet as separate workbook including Master

    Hello All,
    I am using Excel 2010 and I have a workbook with lots of sheet for respective managers
    There is one sheet name "Master' in the workbook followed by each manager sheet


    I found this code on the internet which export ALL sheet as separate workbook

    Sub Splitbook()
    'Updateby20140612
    Dim xPath As String
    xPath = Application.ActiveWorkbook.Path
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    For Each xWs In ThisWorkbook.Sheets
    xWs.Copy
    Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name & ".xls"
    Application.ActiveWorkbook.Close False
    Next
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

    My requirement is to export each sheet AFTER Master sheet together with Master sheet in each newly exported workbook

    eg: if the name of the sheet is John then a new workbook would be created as John.xlsx which will have the two Sheets John and Master similar for all other sheets till the end

    The VBA code should look for the sheet name Master and export the Master and all the sheets followed by Master as separate workbook in the current Path

    Hope this is clear
    Thanks for any help

    Rashid Khan
    Last edited by prkhan56; 06-02-2017 at 09:04 AM.

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to export each sheet after Master Sheet as separate workbook including Master

    Try this
    Put this code in a general module in the workbook containing the sheets to be exported
    Please Login or Register  to view this content.
    NOTE - if you want user to confirm overwrite of file with same name, then remove the 2 DisplayAlerts lines surrounding:
    Please Login or Register  to view this content.
    Last edited by kev_; 06-01-2017 at 05:02 AM.
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Contributor
    Join Date
    06-03-2004
    Location
    India
    MS-Off Ver
    2013
    Posts
    205

    Re: Macro to export each sheet after Master Sheet as separate workbook including Master

    Hi,
    The newly created workbook should have only two Sheets please
    The macro runs and the sheet Master also gets copied
    But can the code be amended to have the newly created Workbook to have only two Sheets
    As the new workbook has Sheet1, Sheet2 and Sheet3 by default

    Thanks for your time and help

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to export each sheet after Master Sheet as separate workbook including Master

    Does this work for you?

    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    06-03-2004
    Location
    India
    MS-Off Ver
    2013
    Posts
    205

    Re: Macro to export each sheet after Master Sheet as separate workbook including Master

    Hello,
    Shall test on my actual data and revert

    Thanks for your time and help once again.
    Regards

  6. #6
    Forum Contributor
    Join Date
    06-03-2004
    Location
    India
    MS-Off Ver
    2013
    Posts
    205

    Re: Macro to export each sheet after Master Sheet as separate workbook including Master

    Hello,
    Thanks for your code. It helped me very much.
    Just couple of things if you can tweak your code please

    1) It should save all the newly created workbooks in a Folder eg:C:\Outputs
    2) I have different version of excel at home and office viz 2010 and 2013. As you may be aware that in 2013 the default sheet is only Sheet1. Would you amend you code to look up number of sheets and then delete Sheet2 and Sheet3 if they exists.

    The above two changes to your existing code will make it more flexible for me to work with

    Hope to get your help and once again thanks for you time

  7. #7
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to export each sheet after Master Sheet as separate workbook including Master

    Rather than checking if sheets exist, accept error if they don't, and move on with this code
    - Replace the 3 original lines with these 5 lines:
    Please Login or Register  to view this content.

    Save to folder:
    Instead of:
    Please Login or Register  to view this content.
    Try:
    Please Login or Register  to view this content.
    Please mark thread as SOLVED
    and it would be nice if you clicked on *Add Reputation to acknowledge the help
    Last edited by kev_; 06-02-2017 at 08:50 AM.

  8. #8
    Forum Contributor
    Join Date
    06-03-2004
    Location
    India
    MS-Off Ver
    2013
    Posts
    205

    Re: Macro to export each sheet after Master Sheet as separate workbook including Master

    Hello,
    Thanks thanks and thanks a lot
    Works great
    Post marked as SOLVED and reputation added

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: Macro to export each sheet after Master Sheet as separate workbook including Master

    you are welcome
    thank you

+ 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. replicating a column from master sheet to other sheets and sorting on the master sheet
    By kstormy1983 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-26-2016, 07:57 PM
  2. Replies: 1
    Last Post: 09-15-2014, 01:03 PM
  3. [SOLVED] Macro to copy data from a master sheet to separate sheet as per date using a macro
    By tmaster81 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-23-2014, 08:05 AM
  4. [SOLVED] VBA / Macro help needed to create separate sheets from Master sheet by year
    By krjoshi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-09-2013, 08:34 AM
  5. Macro to apply a filter from one sheet (a master sheet) to all sheets in workbook
    By SeaniGeld in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-30-2013, 02:00 PM
  6. Master Sheet to Open Specific Sheet from a Separate Workbook
    By jennyaccord in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2011, 10:40 AM
  7. Master sheet into separate sheets then delete macro.
    By motown in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-03-2009, 02:20 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