xxgirlinbluexx
New Member
- Joined
- Jun 17, 2013
- Messages
- 5
I wrote a macro to split a file into rows of 20 and save them each in separate workbooks. It worked the first time round. However, I'm trying the macro a few days after and it no longer works! I only get 1 file with the first 20 rows and the macro stops there. There appear to be no bugs at all. Any way I can fix the problem? I have copied the code here for reference:
Any help is appreciated!
Code:
Sub SplitSheet()
'Split data lines into rows of n lines each and save into another workbook
Dim lastRow As Long, myRow As Long, myBook As Workbook
lastRow = ThisWorkbook.Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For myRow = 1 To lastRow Step 20
Set myBook = Workbooks.Add
ThisWorkbook.Sheets("Sheet1").Rows(myRow & ":" & myRow + 19).EntireRow.Copy myBook.Sheets("Sheet1").Range("A1")
With ActiveWorkbook
.SaveAs Filename:="C:/File" & myRow & ".xls"
.Close
End With
Next myRow
End Sub
Any help is appreciated!