Split table into different workbooks

_Gandour_

New Member
Joined
Nov 16, 2017
Messages
5
Hello guys, i have table with different projects on each row. i need to create a sheet for each row/project mantaining the title row and naming each new workbook as the project name. Is there a way to do it in vba, im really new to this :/

Example:

Original workbook

ProjectCode ProjectName Objective Manager
111 AAA BBB CCC
222 DDD EEE FFF

New Workbook (name: AAA)

ProjectCode ProjectName Objective Manager
111 AAA BBB CCC

New Workbook (name: DDD)

ProjectCode ProjectName Objective Manager
222 DDD EEE FFF



Would Apreciate n help

Thanks in advance.
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
try this.

Code:
Sub Create_xls_File_p1()
Dim Mypath As String
Mypath = Environ("USERPROFILE") & "\Desktop\"

lr = Range("A" & Rows.Count).End(xlUp).Row
For r = 2 To lr

myfile = Mypath & Cells(r, "B") & ".xlsx"
Rows(r).Copy
Set NewBook = Workbooks.Add
  
NewBook.Worksheets("Sheet1").Range("A2").Select
ActiveSheet.Paste

Range("A1:D1").Value = [{"ProjectCode","ProjectName","Objective","Manager"}]
  
NewBook.SaveAs Filename:=myfile 
ActiveWorkbook.Close
Next r

End Sub

hth,

Ross
 
Last edited:
Upvote 0
try this.

Code:
Sub Create_xls_File_p1()
Dim Mypath As String
Mypath = Environ("USERPROFILE") & "\Desktop\"

lr = Range("A" & Rows.Count).End(xlUp).Row
For r = 2 To lr

myfile = Mypath & Cells(r, "B") & ".xlsx"
Rows(r).Copy
Set NewBook = Workbooks.Add
  
NewBook.Worksheets("Sheet1").Range("A2").Select
ActiveSheet.Paste

Range("A1:D1").Value = [{"ProjectCode","ProjectName","Objective","Manager"}]
  
NewBook.SaveAs Filename:=myfile 
ActiveWorkbook.Close
Next r

End Sub

hth,

Ross

Hey Ross, unfortunately your code gave me "Subscript out of Range" Error. My only change to your code was in the range criteria to allow the real names of the sheet

Code:
Sub Create_xls_File_p1()
Dim Mypath As String
Mypath = Environ("USERPROFILE") & "\Desktop\"


lr = Range("A" & Rows.Count).End(xlUp).Row
For r = 2 To lr


myfile = Mypath & Cells(r, "B") & ".xlsx"
Rows(r).Copy
Set NewBook = Workbooks.Add
  
NewBook.Worksheets("Sheet1").Range("A2").Select
ActiveSheet.Paste


Range("A1:G1").Value = [{"Código","Projeto","Servidor Solicitante","Finalidade","Justificativas","Gerente de Projeto","Data de Início de Projeto"}]
  
NewBook.saveas Filename:=myfile
ActiveWorkbook.Close
Next r


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,680
Members
449,116
Latest member
HypnoFant

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