supposed i have a worksheet that has 50 lines
supose i want to automatic create multiple files from this list.
Example
Column A will be the name of the file "column A".xls
Column B should go to A2 in the new file and so on
how can i do this?
supposed i have a worksheet that has 50 lines
supose i want to automatic create multiple files from this list.
Example
Column A will be the name of the file "column A".xls
Column B should go to A2 in the new file and so on
how can i do this?
Last edited by j_r_m_c; 06-08-2012 at 09:30 AM.
no one now ifi it´s possible??
Maybe you could upload your worksheet (or a mockup of your worksheet)?
Attachment 159707i attached a example o the excel file
this shoud create 3 files named
file of John.xls with cell A2=John A4= 34 C5=June 1975
file of Mary.xls with cell A2=Mary A4= 32 C5= May 1980
file of Sue.xls with cell A2=Sue A4= 30 C5= Dezembre 1980
this should be genereated automatic
it´s possible??
Last edited by j_r_m_c; 06-04-2012 at 11:23 AM.
See: j_r_m_c_test to forum.xlsm![]()
Sub CreateFiles() Dim wsThis As Worksheet Dim wbNew As Workbook Dim sPath As String Dim i As Long sPath = ThisWorkbook.Path ' Or for example: sPath = "C:\Users\UserName\Desktop\Development\Test" Set wsThis = ThisWorkbook.Worksheets(1) With wsThis For i = 2 To .Cells(.Rows.Count, "A").End(xlUp).Row Set wbNew = Workbooks.Add ActiveWorkbook.SaveAs sPath & "/" & .Cells(i, "A") wbNew.Worksheets(1).Range("A2") = .Cells(i, "B") wbNew.Worksheets(1).Range("A4") = .Cells(i, "C") wbNew.Worksheets(1).Range("C5") = .Cells(i, "D") wbNew.Close SaveChanges:=True Next i End With End Sub
Thank you
Excelent!!!!
just missing one last question to achive perfection
i have a file in excel where i want to insert this data, so the macro above should use a specific file with some cell already occupied
for example if the cell A2 will be the name than A1 should be "name"... etc
how can i use a specific xls file or use another worksheet???
Last edited by j_r_m_c; 06-04-2012 at 06:09 PM.
I'm having a hard time understanding your question.
Do you want the above code to work with existing worksheets rather than creating new worksheets?
If so, do you want to create a new worksheet when an existing worksheet cannot be found?
If so, so you want to overwrite cells which already have information?
i will have one worksheet wich as cell already occupied with "name" "Age" "Birthday" and with macro above i will create the excel files and insert in each worksheet the information of each line
in attached is the excel with some data that is equal to all and i will use to auto complete with the macro above
Last edited by j_r_m_c; 06-05-2012 at 03:48 AM.
When I create a new workbook and add the name, age and birthday, would you like me to add the headers "Name", "Age", and "Birthday" as well?
Would you like the surrounding region in yellow also?
no, only in the white cell
thank you again for your patient![]()
Last edited by j_r_m_c; 06-05-2012 at 09:30 AM.
How about this?
![]()
Sub CreateFiles() Dim wsThis As Worksheet Dim wbNew As Workbook Dim sPath As String Dim i As Long Dim nLastRow As Long sPath = ThisWorkbook.Path ' Or for example: sPath = "C:\Users\UserName\Desktop\Development\Test" Set wsThis = ThisWorkbook.Worksheets(1) With wsThis nLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row End With For i = 2 To nLastRow Set wbNew = Workbooks.Add ActiveWorkbook.SaveAs sPath & "/" & wsThis.Cells(i, "A") With wbNew.Worksheets(1) .Range("A1") = "Name" .Range("A2") = wsThis.Cells(i, "B") .Range("A3") = "Age" .Range("A4") = wsThis.Cells(i, "C") .Range("C4") = "Birthday" .Range("C5") = wsThis.Cells(i, "D") End With wbNew.Close SaveChanges:=True Next i End Sub
StevenM, i understand this way
but for achive my goal i need to open a file with "Name", "Age", Birthday" already writen
this is a example, the original aplication will have lots of information, and will have more than one sheet.
how can i tell in a macro to open a spefic xls insert some values and save with a diferent name!!
(1) Will all the worksheets be in one folder? And will only those worksheets be in that folder? Or do I get the names of these worksheets from the master worksheet?how can i tell in a macro to open a specific xls insert some values and save with a different name!!
(2) What data do you want to add to these worksheets? I assume that you will have a master worksheet which will contain the new information needed to be added, yes?
(3) How do you want to rename the worksheets?
(4) And in what folder do you want to save these worksheets? The same folder, or different folder?
Before, we had "file of John", "file of Sue" and "file of Mary"
Would you like a macro which opens "John" adds age and birthday, then saves it as "file of John"?
i need to use a xls file with A1, A3,C4 already with this cell
remenber this is a example the use of this function will be for a xls with lot´s of information
if i execute
Last edited by j_r_m_c; 06-06-2012 at 10:13 AM.
For example executing the macro it will use the xls file called "data information" and create 3 files
File of John
File of Mary
File of Sue
each one will have the yellow cells and text, but the information it will be from each person
Last edited by j_r_m_c; 06-06-2012 at 10:19 AM.
1)all in same folder
2) iwill have a master file that i will create lots of file connecting this file with each line from the other file
3)the name of worksheet will be same of A1 (example file of John)
4)in same folder
i hope i was clear in the explanations above
Backup your data.
Change sPath as needed.
This macro opens files found in column A.
Adds headers & info found in columns B, C, & D.
Saves the changes & closes the file.
![]()
Sub CreateFiles() Dim wsThis As Worksheet Dim wb As Workbook Dim sPath As String Dim i As Long Dim nLastRow As Long Dim sFileName As String sPath = ThisWorkbook.Path ' Or for example: sPath = "C:\Users\UserName\Desktop\Development\Test" Set wsThis = ThisWorkbook.Worksheets(1) With wsThis nLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row End With For i = 2 To nLastRow ' File name plus extension xlsx sFileName = wsThis.Cells(i, "A") & ".xlsx" If Dir(sPath & "\" & sFileName) <> sFileName Then MsgBox "Could not find file: " & sFileName Else Set wb = Workbooks.Open(sPath & "\" & sFileName) If wb Is Nothing Then MsgBox "Could not open file: " & wsThis.Cells(i, "A") Else With wb.Worksheets(1) .Range("A1") = "Name" .Range("A2") = wsThis.Cells(i, "B") .Range("A3") = "Age" .Range("A4") = wsThis.Cells(i, "C") .Range("C4") = "Birthday" .Range("C5") = wsThis.Cells(i, "D") End With wb.Close SaveChanges:=True End If End If Next i End Sub
i didn´t understand!!
>
i need a macro to open the data.xls, insert the information collected from info.xls of John in the field A2;A4 and C5, and to finish, save as "A1=file of john.xls", close and star over to the next line in the info.xls file.
reading the macro above i think it doesn´t do like that.
(1) What is "Data.xls"? What is in it?
(2) And what is "info.xls"? What is in it?
(3) How does "text to forum" (which is what I've been using) related to the other files? What file will the macro be stored in?
(4) Will there be a "john.xls"?
(5) And the information is saved in a new "file of john.xls", yes?
i send directly the files
(1) What is "Data.xls"? What is in it? see file attached
(2) And what is "info.xls"? What is in it? see file attached
(3) How does "text to forum" (which is what I've been using) related to the other files? What file will the macro be stored in? I rename as info.xlsm
(4) Will there be a "john.xls"? no
(5) And the information is saved in a new "file of john.xls", yes? the execution of the macro will create file of John.xls; file of Mary.xls; file of Sue.xls
Your file didn't attach. Try again and I'll try to finish the code for you.
Try this: info.xlsm
it does exactly what i want
Thank you StevenM for your patient
excelent!!!!!!!!!!!!!!!!
You are welcome.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks