Results 1 to 12 of 12

save Active tab to new workbooks based on value in column

Threaded View

  1. #1
    Forum Contributor
    Join Date
    03-30-2007
    Location
    London, UK
    MS-Off Ver
    Microsoft Office 2007
    Posts
    317

    Smile save Active tab to new workbooks based on value in column

    Hi Guys

    Some time ago one of the excellent coding guru's here helped me out with a neat macro that would save the active worksheet to a new workbook keeping the original filename and appending the worksheet tab name.

    However I was wondering if this macro could be updated to check for values in column B and when the department name changes save them to separate workbooks. Each department is seperated by a blank row.

    For example if I had a Workbook called 'MyWorkbook.xls' with a tab called 'MyWorkSheet' then in column B2:B3 'Department A' and in B5:B13 had 'Department B' then the macro would scan column B and save 2 new works sheets called 'MyWorkbook - MyWorkSheet-Department A.xls' and 'MyWorkbook - MyWorkSheet-Department B.xls'

    I have included the original code below and I wondered if this could be updated and behaps using the blank rows between departments to let the code know a save should be actioned.

    I would be grateful for any assistance.

    Thanks.

    WorkBook name: 'MyWorkBook.xls'

    Sub SaveActiveSht()
        Dim myPathWhereToSave As String
        Dim wbNm   As String
        myPathWhereToSave = "C:\MyFileLocation\"
    
        wbNm = myPathWhereToSave & Left(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 4)
        Application.ScreenUpdating = False
        ActiveSheet.Copy
        ActiveWorkbook.SaveAs Filename:=wbNm & " - " & ActiveSheet.Name, _
                              FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
                              ReadOnlyRecommended:=False, CreateBackup:=False
    
        ActiveWorkbook.Close
    
        Application.ScreenUpdating = True
    Last edited by Zyphon; 02-26-2010 at 12:48 PM. Reason: Forgot add extension to workbook filename
    Best Regards.

    Michael
    -----------------------------------
    Windows Vista, Microsoft Office 2007

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