How to split data into multiple worksheets based on column in Excel?
Supposing you have a worksheet with huge rows of data, and now, you need to split the data into multiple worksheets based on the Name column (see following screenshots), and the names are entered randomly. Maybe you can sort them first, and then copy and paste them one by one into other new worksheets. But this will need your patience to copy and paste repeatedly. Today, I will talk about some quick tricks to solve this task.
Recommended Productivity Tools
If you want to split the data based on column value quickly and automatically, the following VBA code is a good choice. Please do as this:
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
Sub parse_data() Dim lr As Long Dim ws As Worksheet Dim vcol, i As Integer Dim icol As Long Dim myarr As Variant Dim title As String Dim titlerow As Integer vcol = 1 Set ws = Sheets("Sheet1") lr = ws.Cells(ws.Rows.Count, vcol).End(xlUp).Row title = "A1:C1" titlerow = ws.Range(title).Cells(1).Row icol = ws.Columns.Count ws.Cells(1, icol) = "Unique" For i = 2 To lr On Error Resume Next If ws.Cells(i, vcol) <> "" And Application.WorksheetFunction.Match(ws.Cells(i, vcol), ws.Columns(icol), 0) = 0 Then ws.Cells(ws.Rows.Count, icol).End(xlUp).Offset(1) = ws.Cells(i, vcol) End If Next myarr = Application.WorksheetFunction.Transpose(ws.Columns(icol).SpecialCells(xlCellTypeConstants)) ws.Columns(icol).Clear For i = 2 To UBound(myarr) ws.Range(title).AutoFilter field:=vcol, Criteria1:=myarr(i) & "" If Not Evaluate("=ISREF('" & myarr(i) & "'!A1)") Then Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = myarr(i) & "" Else Sheets(myarr(i) & "").Move after:=Worksheets(Worksheets.Count) End If ws.Range("A" & titlerow & ":A" & lr).EntireRow.Copy Sheets(myarr(i) & "").Range("A1") Sheets(myarr(i) & "").Columns.AutoFit Next ws.AutoFilterMode = False ws.Activate End Sub
Note: In the above code:
- vcol =1, the number 1 is the column number that you want to split the data based on.
- Set ws = Sheets("Sheet1"), Sheet1 is the sheet name that you want to apply this code.
- title = "A1:C1", A1:C1 is the range of the title.
All of them are variables, you can change them as your need.
3. Then press F5 key to run the code, all data in the active worksheet are split into multiple worksheets by the column value. And the split worksheets are named with the split cell names. See screenshot:
Note: The split worksheets are placed in the end of the workbook where the master worksheet is in.
As an Excel beginner, this long VBA code is somewhat difficult for us, and most of us even don't know how to modify the code as our need.
Here, I will introduce you a multifunctional tool--Kutools for Excel, its Split Data utility not only can help you to split data into multiple worksheets based on column, but also can split data by rows count.
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 > Split Data (or Enterprise > Split Data ), see screenshot:
3. In the Split Data into Multiple Worksheets dialog box, you need to:
1). Select Specific column option in the Split based on section, and choose the column value which you want to split the data based on in the drop-down list. (If your data has headers and you want to insert them into each new split worksheet, please check My data has headers option.)
2). Then you can specify the split worksheet names, under the New worksheets name section, specify the worksheet names rules from the Rules drop down list, you can add the Prefix or Suffix for the sheet names as well.
3). Click the OK button. See screenshot:
Now the data are split into multiple worksheets in a new workbook.
Kutools for Excel includes more than 120 handy Excel tools. Free to try with no limitation in 60 days. Download the free trial now!
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!
200 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.· 20 days agoThank you! Split data with VBA is an excellent time saver! The only issue that I had is when data in vcol is not a valid tab name. Is there a way to truncate the name to something allowed or populate the data even if the sheet name is "Sheet" #? It created blank sheets named "Sheet" # instead of putting the data on the sheet.
To post as a guest, your comment is unpublished.· 26 days agoHi
I have split the data using VBA and the result was good except that I am getting 2 blank sheet.
For Eg. Total sheet as per filter needed 70 sheet but got only 68sheets and 2 sheets were blank.
Can someone help me with this ??
To post as a guest, your comment is unpublished.· 28 days agoWhen I use this to split the data, I lose all formulas including conditional formatting. I also want to include subtotal in the last column on all sheets. How to do this?
To post as a guest, your comment is unpublished.· 1 months agoPost #4 on this page does what this should do and doesn't crash my computer like this did!
To post as a guest, your comment is unpublished.· 1 months agoHi, this worked fine once and then i get runtime error '9' subscript out of range at line Set ws = Sheets("[NAME]").
Why would this be happening?
- ← Previous
- Next →