How to split data into multiple worksheets by rows count in Excel?
For example, I have a range of data list, now I want to split it into multiple worksheets by rows count, in this example, I will split it by every 5 rows (see following screenshots). Are there any ways to help us solve this problem quickly? Here I will introduce two tricks for you to get it done easily.
Recommended Productivity Tools for Excel/Office
The following VBA code can help you split the rows into multiple worksheets by rows count, do as follows:
1. Hold down the ALT + F11 key to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA: Split data into sheets by rows count in Excel.
Sub SplitData() 'Updateby20140617 Dim WorkRng As Range Dim xRow As Range Dim SplitRow As Integer Dim xWs As Worksheet On Error Resume Next xTitleId = "KutoolsforExcel" Set WorkRng = Application.Selection Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8) SplitRow = Application.InputBox("Split Row Num", xTitleId, 5, Type:=1) Set xWs = WorkRng.Parent Set xRow = WorkRng.Rows(1) Application.ScreenUpdating = False For i = 1 To WorkRng.Rows.Count Step SplitRow resizeCount = SplitRow If (WorkRng.Rows.Count - xRow.Row + 1) < SplitRow Then resizeCount = WorkRng.Rows.Count - xRow.Row + 1 xRow.Resize(resizeCount).Copy Application.Worksheets.Add after:=Application.Worksheets(Application.Worksheets.Count) Application.ActiveSheet.Range("A1").PasteSpecial Set xRow = xRow.Offset(SplitRow) Next Application.CutCopyMode = False Application.ScreenUpdating = True End Sub
3. Then press F5 key to run the code, and a dialog pops out for selecting a range to split, and then click OK, and another dialog for you to specify the rows count. See screenshot:
4. Click OK, and the range are split into multiple sheets by the rows count.
Note: The split worksheets are placed at the back of the master worksheet.
The above code can only split the data by the specified rows count, and it will not add the title for each worksheet data if your data has the title.
But with Kutools for Excel’s Split Data, you not only can insert the headers for each worksheet data, but also can specify the new split worksheet names.
If you have installed Kutools for Excel, please do as follows:
1. Select the range of data that you want to split.
2. Click Enterprise > Worksheet Tools > Split Data (or Enterprise > Split Data ), see screenshot:
3. In the Split Data into Multiple Worksheets dialog box:
- Select Fixed rows from Split based on option, and enter the number of rows count that you want to split for each worksheets. (If your data has headers and you want to insert them into each new split worksheet, please check My data has headers option.)
- Then you can specify the split worksheet names, under the New worksheets name section, select the worksheet names rules from the Rules drop down list, you can add the Prefix or Suffix for the sheet names as well. See screenshot:
4. After specify the settings, then click OK, and the selected data has been split into multiple worksheets of a new workbook by every 5 rows. And the headers are inserted for each new worksheet. See screenshot:
Recommended Productivity Tools
Bring handy tabs to Excel and other Office software, just like Chrome, Firefox and new Internet Explorer.
Amazing! Increase your productivity in 5 minutes. Don't need any special skills, save two hours every day!
300 New Features for Excel, Make Excel Much Easy and Powerful:
- Merge Cell/Rows/Columns without Losing Data.
- Combine and Consolidate Multiple Sheets and Workbooks.
- Compare Ranges, Copy Multiple Ranges, Convert Text to Date, Unit and Currency Conversion.
- Count by Colors, Paging Subtotals, Advanced Sort and Super Filter,
- More Select/Insert/Delete/Text/Format/Link/Comment/Workbooks/Worksheets Tools...
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 8 months agoOmg thank you so very much dude!
To post as a guest, your comment is unpublished.· 1 years agoHi Thanks for this great code, but the concern is, here we can only split fixed number of rows, can you help me with split is based on some name or code, because i have different set of rows for each worksheet.
To post as a guest, your comment is unpublished.· 1 years agohi this works great but want the output as string how can i modify the code or i can say example : 'output',
To post as a guest, your comment is unpublished.· 1 years agoThanks a lot for the fantastic VBA-Script. But how to modify it to keep the header row on every split?
To post as a guest, your comment is unpublished.· 1 years agoThanks, for this fantastic VBA-Script. But how to configure it to repeat the header row on every split?