View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Can I split up an excel spreadsheet into multiple files by row

One way is with a macro:

Option Explicit
Sub testme()

Dim curWks As Worksheet
Dim newWks As Worksheet

Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long

Set curWks = Worksheets("sheet1")
Set newWks = Workbooks.Add(1).Worksheets(1)

With curWks
FirstRow = 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

For iRow = FirstRow To LastRow
.Rows(iRow).Copy
With newWks.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With
newWks.Parent.SaveAs _
Filename:="C:\temp\" & Format(iRow, "0000") & ".csv", _
FileFormat:=xlCSV
Next iRow
End With

newWks.Parent.Close savechanges:=False

End Sub

This routine expects to have an existing folder named c:\temp. It creates files
named ####.csv based on the row number.

If you run this a second time, you'll want to clean up that folder first--else
you'll be answer yes/no to each of the overwrite prompts.

I figure it's a safe way not to destroy important existing data.


If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

seespot wrote:

Each row is made up of numeric and text data in approximately 100 cells. I
would like to see each row in a new .csv of its own.

"Dave Peterson" wrote:

And do you want those files saved as .xls files or .txt files (or something
else)?

seespot wrote:

I have an excel spread sheet of many many rows and I would like to split
every row out into its own file. Is there an easy way to do this?


--

Dave Peterson


--

Dave Peterson