View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
JulieD JulieD is offline
external usenet poster
 
Posts: 618
Default 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