Split worksheet into multiple files by every nth row

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
rashaan78
Posts: 1
Joined: Thu Jul 10, 2008 5:10 pm

Split worksheet into multiple files by every nth row

Post by rashaan78 »

Hi,

I have a master worksheet that I would like to split into individual files according to every nth row (say 50). Essentially, the first file would have the first 50 rows of data, the second file would have the second 50 rows of data, and so on. Also, I'd like the header row in the master worksheet to be the header row for each of the split files. (yikes!)

The VBA code pasted below accomplishes this in Excel (minus the recurring header row) but I would would much rather continue to use Calc in the process. Unfortunately, I don't know enough to either "translate" this code for use in OpenOffice or to create a new script from scratch. Any help would be greatly appreciated.

Thanks!

Code: Select all

Sub Macro1()
    Dim rLastCell As Range
    Dim rCells As Range
    Dim strName As String
    Dim lLoop As Long, lCopy As Long
    Dim wbNew As Workbook
     
    With ThisWorkbook.Sheets(1)
        Set rLastCell = .Cells.Find(What:="*", After:=[A1], SearchDirection:=xlPrevious)
         
        For lLoop = 1 To rLastCell.Row Step 50
            lCopy = lCopy + 1
            Set wbNew = Workbooks.Add
            .Range(.Cells(lLoop, 1), .Cells(lLoop + 50, .Columns.Count)).EntireRow.Copy _
            Destination:=wbNew.Sheets(1).Range("A1")
            wbNew.Close SaveChanges:=True, Filename:="Reservations_" & lLoop + 49
        Next lLoop
    End With
     
     
End Sub
OOo 2.4.X on Ms Windows XP
Post Reply