Split a single spreadsheet in XLS into multiple new workbooks

craigfer

New Member
Joined
May 16, 2012
Messages
29
Office Version
  1. 365
I have a software that i need to upload information. The software has a 500 line limit on the Excel file import.
I have 84,968 lines of data in a single workbook. Is there a way of splitting up this data into the 169 seperate workbooks (induvidual files not worksheets).
These new workbooks need to be named differently. I can add a Batch column in the original file and give the cell a name so the first 500 lines would be BAT001, the next 500 would be BAT002
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Try this macro - no need for the Batch column.

VBA Code:
Public Sub Split_Sheet_Into_New_Workbooks()

    Dim rangeToCopy As Range
    Dim wbCount  As Long
    Dim maxRows As Long
    Dim r As Long, c As Long
    Dim wb As Workbook

    maxRows = 500
    wbCount = 1
    
    Application.ScreenUpdating = False
        
    With ActiveWorkbook.ActiveSheet
        c = .Cells(1, .Columns.Count).End(xlToLeft).Column
        For r = 1 To .Cells(.Rows.Count, 1).End(xlUp).Row Step maxRows
            Set wb = Workbooks.Add
            Set rangeToCopy = .Cells(r, 1).Resize(maxRows, c)
            rangeToCopy.Copy wb.Worksheets(1).Range("A1")
            Application.DisplayAlerts = False
            wb.SaveAs ThisWorkbook.Path & "\BAT" & Format(wbCount, "000") & ".xlsx", FileFormat:=xlOpenXMLWorkbook
            Application.DisplayAlerts = True
            wb.Close
            wbCount = wbCount + 1
        Next
    End With
    
    Application.ScreenUpdating = True

End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,223,923
Messages
6,175,392
Members
452,640
Latest member
steveridge

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top