Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Question for complicated merge
Hi Jason
here's some code that takes each row in turn, starting at row 2 and puts it into a new workbook and then saves the workbook using the name in cell G1. Sub SplitWorkbook() Do Until Range("A2").Value = "" Rows("2:2").Select Selection.Cut Workbooks.Add ActiveSheet.Paste Range("A1").Select ActiveWorkbook.SaveAs Filename:=Range("G1"), FileFormat:=xlNormal, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWindow.Close Selection.Delete Shift:=xlUp Loop End Sub Please post back if you require further assistance. Regards JulieD "Jason L" wrote in message ... Hey, I'm very new to Excel and especially to Excel programming. I'm currently working on a template that will allow a user to import data from a txt file into an excel template. This text file has multiple records in it, and each one has to be stored in a seperate excel file under a specific field entry (field G3). I've been doing this in Word, but Word's limitations with tables and comment problems has been limiting. Right now my idea is to merge the entire file into an Excel sheet and run a macro that will split each row into a separate excel worksheet with the specific name. These files then need to be merged into another template that has the proper field headers. This template also has user instructions entered into fields some of the higher numbered fields. The user modifies these higher numbered fields and then will save this document and merge it into a Word document. Here is the code I have for the splitting and saving of the excel worksheets. I'd appreciate any insight or feedback here. This code is essentially supposed to take each row in the first excel sheet, grab the whole row, dump it into my template and save it according to the name located in G3. Thanks again for your help. Sub BRPT() Dim fname As String Range("G3").Select fname = Selection Dim i As Integer, Source As Worksheet, Target As Worksheet Set Source = ActiveWorkbook For i = 1 To Source.Rows.Count Set Target = Worksheet.Add Target.Range = Source.Rows(i).Range Target.SaveAs Filename:=fname & ".xls" Target.Close Set Target = Nothing Next i Set Source = Nothing End Sub -TIA, Jason |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Question for complicated merge
Hi Jason
you're pasting before you're selecting & you're not deleting the row only cutting the data try --- Sub SplitWorkbook() Do Until Range("A1").Value = "" 'Since there are no field headers in the original file, I just had it select the first row and cut. Rows("1:1").Select Selection.Cut Workbooks.Add Template:="BRPT1.xlt" 'The name of the template is BRPT1.xlt. Range("A2").Select ActiveSheet.Paste 'Since there are headers in the template, the rows need to be dropped down one row when they are pasted into the file. ActiveWorkbook.SaveAs Filename:=Range("G2"), FileFormat:=xlNormal, _ Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWindow.Close Selection.Delete Shift:=xlUp Loop End Sub --- Cheers JulieD "Jason L" wrote in message ... JulieD, Thanks a lot. This is very close to what I want. As I was testing it, I realized that I was wrong in some of my assumptions. First, the downloaded info can go into a regular, blank worksheet. It's from there that it needs to be split off and imported into separate workbooks with my created field headers. Essentially, I need to do the same procedure, but I need to use a specific template that includes field headers. I changed the code some to allow this, but I keep getting a 400 error. Here is my code thus far: Sub SplitWorkbook() Do Until Range("A1").Value = "" 'Since there are no field headers in the original file, I just had it select the first row and cut. Rows("1:1").Select Selection.Cut Workbooks.Add Template:="BRPT1.xlt" 'The name of the template is BRPT1.xlt. ActiveSheet.Paste Range("A2").Select 'Since there are headers in the template, the rows need to be dropped down one row when they are pasted into the file. ActiveWorkbook.SaveAs Filename:=Range("G2"), FileFormat:=xlNormal, _ Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWindow.Close Loop End Sub TIA, Jason "JulieD" wrote: Hi Jason here's some code that takes each row in turn, starting at row 2 and puts it into a new workbook and then saves the workbook using the name in cell G1. Sub SplitWorkbook() Do Until Range("A2").Value = "" Rows("2:2").Select Selection.Cut Workbooks.Add ActiveSheet.Paste Range("A1").Select ActiveWorkbook.SaveAs Filename:=Range("G1"), FileFormat:=xlNormal, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWindow.Close Selection.Delete Shift:=xlUp Loop End Sub Please post back if you require further assistance. Regards JulieD "Jason L" wrote in message ... Hey, I'm very new to Excel and especially to Excel programming. I'm currently working on a template that will allow a user to import data from a txt file into an excel template. This text file has multiple records in it, and each one has to be stored in a seperate excel file under a specific field entry (field G3). I've been doing this in Word, but Word's limitations with tables and comment problems has been limiting. Right now my idea is to merge the entire file into an Excel sheet and run a macro that will split each row into a separate excel worksheet with the specific name. These files then need to be merged into another template that has the proper field headers. This template also has user instructions entered into fields some of the higher numbered fields. The user modifies these higher numbered fields and then will save this document and merge it into a Word document. Here is the code I have for the splitting and saving of the excel worksheets. I'd appreciate any insight or feedback here. This code is essentially supposed to take each row in the first excel sheet, grab the whole row, dump it into my template and save it according to the name located in G3. Thanks again for your help. Sub BRPT() Dim fname As String Range("G3").Select fname = Selection Dim i As Integer, Source As Worksheet, Target As Worksheet Set Source = ActiveWorkbook For i = 1 To Source.Rows.Count Set Target = Worksheet.Add Target.Range = Source.Rows(i).Range Target.SaveAs Filename:=fname & ".xls" Target.Close Set Target = Nothing Next i Set Source = Nothing End Sub -TIA, Jason |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Question for complicated merge
Hi Jason
did you get it working? Cheers JulieD "JulieD" wrote in message ... Hi Jason you're pasting before you're selecting & you're not deleting the row only cutting the data try --- Sub SplitWorkbook() Do Until Range("A1").Value = "" 'Since there are no field headers in the original file, I just had it select the first row and cut. Rows("1:1").Select Selection.Cut Workbooks.Add Template:="BRPT1.xlt" 'The name of the template is BRPT1.xlt. Range("A2").Select ActiveSheet.Paste 'Since there are headers in the template, the rows need to be dropped down one row when they are pasted into the file. ActiveWorkbook.SaveAs Filename:=Range("G2"), FileFormat:=xlNormal, _ Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWindow.Close Selection.Delete Shift:=xlUp Loop End Sub --- Cheers JulieD "Jason L" wrote in message ... JulieD, Thanks a lot. This is very close to what I want. As I was testing it, I realized that I was wrong in some of my assumptions. First, the downloaded info can go into a regular, blank worksheet. It's from there that it needs to be split off and imported into separate workbooks with my created field headers. Essentially, I need to do the same procedure, but I need to use a specific template that includes field headers. I changed the code some to allow this, but I keep getting a 400 error. Here is my code thus far: Sub SplitWorkbook() Do Until Range("A1").Value = "" 'Since there are no field headers in the original file, I just had it select the first row and cut. Rows("1:1").Select Selection.Cut Workbooks.Add Template:="BRPT1.xlt" 'The name of the template is BRPT1.xlt. ActiveSheet.Paste Range("A2").Select 'Since there are headers in the template, the rows need to be dropped down one row when they are pasted into the file. ActiveWorkbook.SaveAs Filename:=Range("G2"), FileFormat:=xlNormal, _ Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWindow.Close Loop End Sub TIA, Jason "JulieD" wrote: Hi Jason here's some code that takes each row in turn, starting at row 2 and puts it into a new workbook and then saves the workbook using the name in cell G1. Sub SplitWorkbook() Do Until Range("A2").Value = "" Rows("2:2").Select Selection.Cut Workbooks.Add ActiveSheet.Paste Range("A1").Select ActiveWorkbook.SaveAs Filename:=Range("G1"), FileFormat:=xlNormal, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False ActiveWindow.Close Selection.Delete Shift:=xlUp Loop End Sub Please post back if you require further assistance. Regards JulieD "Jason L" wrote in message ... Hey, I'm very new to Excel and especially to Excel programming. I'm currently working on a template that will allow a user to import data from a txt file into an excel template. This text file has multiple records in it, and each one has to be stored in a seperate excel file under a specific field entry (field G3). I've been doing this in Word, but Word's limitations with tables and comment problems has been limiting. Right now my idea is to merge the entire file into an Excel sheet and run a macro that will split each row into a separate excel worksheet with the specific name. These files then need to be merged into another template that has the proper field headers. This template also has user instructions entered into fields some of the higher numbered fields. The user modifies these higher numbered fields and then will save this document and merge it into a Word document. Here is the code I have for the splitting and saving of the excel worksheets. I'd appreciate any insight or feedback here. This code is essentially supposed to take each row in the first excel sheet, grab the whole row, dump it into my template and save it according to the name located in G3. Thanks again for your help. Sub BRPT() Dim fname As String Range("G3").Select fname = Selection Dim i As Integer, Source As Worksheet, Target As Worksheet Set Source = ActiveWorkbook For i = 1 To Source.Rows.Count Set Target = Worksheet.Add Target.Range = Source.Rows(i).Range Target.SaveAs Filename:=fname & ".xls" Target.Close Set Target = Nothing Next i Set Source = Nothing End Sub -TIA, Jason |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
IF question complicated | Excel Discussion (Misc queries) | |||
Complicated Mail Merge that is over my head. | Excel Discussion (Misc queries) | |||
Complicated mail merge | Excel Discussion (Misc queries) | |||
Complicated question | Excel Discussion (Misc queries) | |||
Complicated Question | Excel Worksheet Functions |