Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default multiple files from one file

Hi there;
I have a file with below structu
A1: name
A2:E93 contain data
then
A94: name
A95:E186 contain data
then again
continues till:
A5860: name
A5861:E5952 contain data

each set of data are 91 cells (in a coulmn) after each set there is one row
which in its A column is name. Now what I want is how to make an Excel file
for each 91 set of data (91 Col., 5 Rows) and save them with the names comes
in A cell for that data came as name. So basically I shoudl have many files
which contain just one set of data and keep the original file as it is?
Appreciate any help for this.
Best
Darius

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default multiple files from one file

This worked ok for me:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim newWks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim myStep As Long
Dim myCols As Long

myStep = 91
myCols = 5

Set wks = Worksheets("Sheet1")

Set newWks = Workbooks.Add(1).Worksheets(1)

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

For iRow = FirstRow To LastRow Step myStep
.Cells(iRow + 1).Resize(myStep, myCols).Copy _
Destination:=newWks.Range("a1")
Application.DisplayAlerts = False
newWks.Parent.SaveAs _
Filename:="C:\temp\" & .Cells(iRow, "A").Value & ".xls", _
FileFormat:=xlWorkbookNormal
Application.DisplayAlerts = True
newWks.UsedRange.Clear
Next iRow
End With

newWks.Parent.Close savechanges:=False

End Sub

I put the files in C:\temp. That folder has to exist.

And any existing files with the same name are overwritten with the new file.
Application.displayalerts stops excel from prompting you.

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


Darius wrote:

Hi there;
I have a file with below structu
A1: name
A2:E93 contain data
then
A94: name
A95:E186 contain data
then again
continues till:
A5860: name
A5861:E5952 contain data

each set of data are 91 cells (in a coulmn) after each set there is one row
which in its A column is name. Now what I want is how to make an Excel file
for each 91 set of data (91 Col., 5 Rows) and save them with the names comes
in A cell for that data came as name. So basically I shoudl have many files
which contain just one set of data and keep the original file as it is?
Appreciate any help for this.
Best
Darius


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default multiple files from one file

Actually, that didn't work ok for me.

But this one did:

Option Explicit
Sub testme()

Dim wks As Worksheet
Dim newWks As Worksheet
Dim iRow As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim myStep As Long
Dim myCols As Long

myStep = 91
myCols = 5

Set wks = Worksheets("Sheet1")

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

For iRow = FirstRow To LastRow Step myStep
Set newWks = Workbooks.Add(1).Worksheets(1)
.Cells(iRow + 1, "A").Resize(myStep, myCols).Copy _
Destination:=newWks.Range("a1")
Application.DisplayAlerts = False
newWks.Parent.SaveAs _
Filename:="C:\temp\" & .Cells(iRow, "A").Value & ".xls", _
FileFormat:=xlWorkbookNormal
Application.DisplayAlerts = True
newWks.Parent.Close savechanges:=False
Next iRow
End With


End Sub




Dave Peterson wrote:

This worked ok for me:

<<snipped

I put the files in C:\temp. That folder has to exist.

And any existing files with the same name are overwritten with the new file.
Application.displayalerts stops excel from prompting you.

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

Darius wrote:

Hi there;
I have a file with below structu
A1: name
A2:E93 contain data
then
A94: name
A95:E186 contain data
then again
continues till:
A5860: name
A5861:E5952 contain data

each set of data are 91 cells (in a coulmn) after each set there is one row
which in its A column is name. Now what I want is how to make an Excel file
for each 91 set of data (91 Col., 5 Rows) and save them with the names comes
in A cell for that data came as name. So basically I shoudl have many files
which contain just one set of data and keep the original file as it is?
Appreciate any help for this.
Best
Darius


--

Dave Peterson


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
combine information from multiple file into many different files. RW Excel Worksheet Functions 2 June 8th 08 06:33 PM
Convert one .csv file to multiple excel files singh Excel Discussion (Misc queries) 1 October 9th 07 01:02 AM
How do I merge multiple xls files into one file? Steve Excel Discussion (Misc queries) 5 April 26th 07 08:28 PM
Copying Multiple files in one file Macro - Liz Liz New Users to Excel 2 March 13th 07 02:45 PM
How do I merge multiple xls files into one file? Gianni Excel Discussion (Misc queries) 3 June 14th 05 02:09 PM


All times are GMT +1. The time now is 03:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"