Save tabs in new worksheets depending on name of tabs

CRMTHB

New Member
Joined
Mar 12, 2019
Messages
13
Hi,

I have multiple tabs on a worksheet, and I want each individual tab to be saved in a location depending on the name of the tab. The actual name of the file would be the tab name, plus the contents of cell A1.

So for example, if the tab is called "Bananas" and has "1234" in cell A1, the tab is to be saved as a new worksheet called "Bananas 1234" in location Q:\Departments\XX\ZZ\Bananas.

Is this possible? Any help would be appreciated
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try:
Code:
Sub SaveSheets()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    For Each ws In Sheets
        ws.Copy
        ActiveWorkbook.SaveAs Filename:="Q:\Departments\XX\ZZ\" & ActiveSheet.Name & "\" & ActiveSheet.Name & ActiveSheet.Range("A1").Value & ".xlsx"
        ActiveWorkbook.Close False
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks mumps, that is working well, although it does fail if there no folder exists with that name.

I assume it is not possible for an excel macro to create a new folder?
 
Upvote 0
How about
Code:
Sub crmthb()
   Dim Ws As Worksheet
   Dim Pth As String
   
   For Each Ws In Worksheets
       Pth = "Q:\Departments\XX\ZZ\" & Ws.Name & "\"
       If Dir(Pth, vbDirectory) = "" Then MkDir Pth
       Ws.Copy
       ActiveWorkbook.SaveAs Pth & ActiveSheet.Name & ActiveSheet.Range("A1").Value & ".xlsx", 51
       ActiveWorkbook.Close False
   Next Ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,817
Messages
6,121,720
Members
449,050
Latest member
MiguekHeka

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top