Consulting

Results 1 to 5 of 5

Thread: Save specific sheets as separate workbooks

  1. #1
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location

    Save specific sheets as separate workbooks

    Hi, long time no sea!

    I would like to have Sheets 3, 4, 5, 6, 7 and 8 of a 10-sheet workbook saved as six individual workbooks (in the same location as wherever the current workbook is saved in). IE each new wb will consist of only the one sheet.

    Columns B & C need to have all formulae converted to values

    The Names that appear on the sheet tabs may be changed by the user, so i need vba to ignore them and use the hidden vba name for the sheets which is sheet3, sheet4 etc.

    the filename for the sheet needs to be a date (yyyy/mm) a space and whatever is in cell B2 of each of the sheets.

    Any help would be greatly appreciated.

    thanks

    Sir BD
    Last edited by Sir Babydum GBE; 03-01-2019 at 06:13 AM.
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    I'd just do something simple like this


    Option Explicit
    
    Sub MakeSomeWorkbooks()
        Application.ScreenUpdating = False
        Application.CalculateFull
        CopySheet Sheet3
        CopySheet Sheet4
        CopySheet Sheet5
        CopySheet Sheet6
        CopySheet Sheet7
        CopySheet Sheet8
        Application.ScreenUpdating = True
    End Sub
    
    
    
    
    Private Sub CopySheet(ws As Worksheet)
        Dim wb As Workbook
        Dim sFile As String
        
        sFile = ws.Parent.Path & Application.PathSeparator & Format(Date, "yyyy-mm") & " " & ws.Range("B2").Text
        
        ws.Copy
        Set wb = ActiveWorkbook
        
        wb.SaveAs sFile, xlOpenXMLWorkbook
        wb.Close
        
        ThisWorkbook.Activate
    End Sub
    
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    If you have a lot of formulas to convert to values, it would probably be faster for the macro to copy the workbook, change columns B and C as I did, and then work from there. That would also eliminate the extra save.

    If don't have a lot of data, this change to Paul's routine should suffice.

    Private Sub CopySheet(ws As Worksheet)    
      Dim sFile As String, r As Range
        
        sFile = ws.Parent.Path & Application.PathSeparator & Format(Date, "yyyy-mm") & " " & ws.Range("B2").Text
        
        ws.Copy
        With ActiveWorkbook
          .SaveAs sFile, xlOpenXMLWorkbook
          Set r = Intersect(.Worksheets(1).UsedRange, .Worksheets(1).Columns("B:C"))
          r.Value = r.Value
          .Save
          .Close
        End With
        
        ThisWorkbook.Activate
    End Sub

  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,726
    Location
    Yea, I forgot the B:C to values part
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  5. #5
    VBAX Mentor Sir Babydum GBE's Avatar
    Joined
    Mar 2005
    Location
    Cardiff, UK
    Posts
    499
    Location
    Thanks both. That worked perfectly. Thanks for your time and sorry for the delay in my response.
    Have a profound problem? Need a ridiculous solution? Post a question in Babydum's forum

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •