Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default Creating mulitple workbooks from single workbook - *Macro tweaking needed*

I found this macro in the forums and it works great. What is does is
create a seperate CSV file for every row in the workbook.

What I would like to do though is create a file for every 25 rows. I
also would like to make the files .XLS, not .CSV.

Can anyone assist in tweaking this macro for me? Thanks!

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 = 2 'headers in row 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row


.Rows(1).Copy
With newWks.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With


For iRow = FirstRow To LastRow
.Rows(iRow).Copy
With newWks.Range("a2")
.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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Creating mulitple workbooks from single workbook - *Macro tweakingneeded*

Still keep the first row as a header row?

(Untested, but it did compile)

Option Explicit
Sub testme()

Dim curWks As Worksheet
Dim newWks As Worksheet

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

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

myStep = 25

With curWks
FirstRow = 2 'headers in row 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

.Rows(1).Copy
With newWks.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With

For iRow = FirstRow To LastRow Step myStep
.Rows(iRow).Resize(myStep).Copy
With newWks.Range("a2")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With
newWks.Parent.SaveAs _
Filename:="C:\temp\" & Format(iRow, "0000") & ".xls", _
FileFormat:=xlWorkbookNormal
Next iRow
End With

newWks.Parent.Close savechanges:=False

End Sub


Dan wrote:

I found this macro in the forums and it works great. What is does is
create a seperate CSV file for every row in the workbook.

What I would like to do though is create a file for every 25 rows. I
also would like to make the files .XLS, not .CSV.

Can anyone assist in tweaking this macro for me? Thanks!

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 = 2 'headers in row 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

.Rows(1).Copy
With newWks.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With

For iRow = FirstRow To LastRow
.Rows(iRow).Copy
With newWks.Range("a2")
.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


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 41
Default Creating mulitple workbooks from single workbook - *Macro tweaking needed*

On Feb 15, 3:31 pm, Dave Peterson wrote:
Still keep the first row as a header row?

(Untested, but it did compile)

Option Explicit
Sub testme()

Dim curWks As Worksheet
Dim newWks As Worksheet

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

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

myStep = 25

With curWks
FirstRow = 2 'headers in row 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

.Rows(1).Copy
With newWks.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With

For iRow = FirstRow To LastRow Step myStep
.Rows(iRow).Resize(myStep).Copy
With newWks.Range("a2")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With
newWks.Parent.SaveAs _
Filename:="C:\temp\" & Format(iRow, "0000") & ".xls", _
FileFormat:=xlWorkbookNormal
Next iRow
End With

newWks.Parent.Close savechanges:=False

End Sub





Dan wrote:

I found this macro in the forums and it works great. What is does is
create a seperate CSV file for every row in the workbook.


What I would like to do though is create a file for every 25 rows. I
also would like to make the files .XLS, not .CSV.


Can anyone assist in tweaking this macro for me? Thanks!


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 = 2 'headers in row 1
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row


.Rows(1).Copy
With newWks.Range("A1")
.PasteSpecial Paste:=xlPasteValues
.PasteSpecial Paste:=xlPasteFormats
End With


For iRow = FirstRow To LastRow
.Rows(iRow).Copy
With newWks.Range("a2")
.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


--

Dave Peterson- Hide quoted text -

- Show quoted text -


Perfect! Thanks so much!!
Dan

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
Can mulitple Excel workbooks be summarized into 1 workbook? micjil Excel Discussion (Misc queries) 1 July 15th 09 08:23 PM
merge columns into single report - macro needed aquaflow Excel Discussion (Misc queries) 2 February 5th 07 12:41 PM
Creating a single workbook from multiple workbooks Scrum Down Excel Discussion (Misc queries) 3 September 6th 06 09:01 AM
Creating multiple workbooks from summary workbook encise Excel Discussion (Misc queries) 2 November 2nd 05 11:35 PM
creating new workbook from single worksheet Shaun[_3_] Excel Programming 3 January 3rd 04 02:29 AM


All times are GMT +1. The time now is 09:58 PM.

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

About Us

"It's about Microsoft Excel"