Saving split worksheets into specific folders

micashell

New Member
Joined
Mar 3, 2018
Messages
4
Hoping someone can help.

I can find code for various parts of what I want to do but I can't find everything.

I have a summary sheet where column A has a list of names. Column C has a list of sheet names. Those sheet names form the rest of the workbook

I want to split the workbook and save the individual sheets with the sheet names as the file name (I have code for this. The code doesn't use column C, it just uses the sheet names). However, those sheet names are in column C in case that makes it easier for someone to create the code

I want to create folders with the names in column A. (I have code for this).

What I am missing is that I want to save the files created into the folders created. These folders will be in one location, I just need the sheets to go into corresponding folder name.

I am not precious about the code I have if someone has something that can spit the workbook, create the folder and save the file in the folder all in one.

All help gratefully received
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi & welcome to MrExcel
How about
Code:
Sub SplitWbk()

   Dim Wbk As Workbook
   Dim Ws As Worksheet
   Dim Pth As String
   
Application.ScreenUpdating = False
   Set Wbk = ActiveWorkbook
   Pth = "C:\MrExcel\test\"
   
   For Each Ws In Wbk.Worksheets
      If Ws.Name <> "Moderation" Then
         If Dir(Pth & Ws.Name, vbDirectory) = "" Then MkDir Pth & Ws.Name
         Ws.Copy
         ActiveWorkbook.SaveAs Pth & Ws.Name & "\" & Ws.Name, 52
         ActiveWorkbook.Close False
      End If
   Next Ws
End Sub
 
Upvote 0
Hi Fluff and thank you so much for your speedy response. That code is amazing and it's almost there but it is making the folder name the same as the file name. I need the folder name to read from column A which has a name in it whereas column C has the sheet name in it but the two are not the same. is it possible to amend the above code to fix that?
 
Upvote 0
Do you want the files named as per col A, or as per the sheet name?
 
Upvote 0
I'm basically looking for the result c:\desktop\holding folder\column A\sheetname.xlsx - although sheetname.xlsx could be column C.xlsx and it would be the same
 
Upvote 0
Ok, try
Code:
Sub SplitWbk()

   Dim Cl As Range
   Dim Pth As String
   
Application.ScreenUpdating = False
   Pth = "C:\MrExcel\test\"
   
   For Each Cl In Range("A3", Range("A" & Rows.Count).End(xlUp))
         If Dir(Pth & Cl.Value, vbDirectory) = "" Then MkDir Pth & Cl.Value
         Sheets(Cl.Offset(, 2).Value).Copy
         ActiveWorkbook.SaveAs Pth & Cl.Value & "\" & Cl.Offset(, 2).Value, 52
         ActiveWorkbook.Close False
   Next Cl
End Sub
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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