How to split a long list into equal groups in Excel?
If you have a long list of data needed to be split into multiple equal groups as following screenshot shown, how could you deal with this task quickly and easily in Excel?
Excepting copy and paste the data one by one, the following VBA code also can do you a favor, please do with following steps:
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.
VBA code: Split a long list into multiple equal groups
Sub SplitIntoCellsPerColumn() 'updateby Extendoffice Dim xRg As Range Dim xOutRg As Range Dim xCell As Range Dim xTxt As String Dim xOutArr As Variant Dim I As Long, K As Long On Error Resume Next xTxt = ActiveWindow.RangeSelection.Address Sel: Set xRg = Nothing Set xRg = Application.InputBox("please select data range:", "Kutools for Excel", xTxt, , , , , 8) If xRg Is Nothing Then Exit Sub If xRg.Areas.Count > 1 Then MsgBox "does not support multiple selections, please select again", vbInformation, "Kutools for Excel" GoTo Sel End If If xRg.Columns.Count > 1 Then MsgBox "does not support multiple columns,please select again", vbInformation, "Kutools for Excel" GoTo Sel End If Set xOutRg = Application.InputBox("please select a cell to put the result:", "Kutools for Excel", , , , , , 8) If xOutRg Is Nothing Then Exit Sub I = Application.InputBox("the number of cell per column:", "Kutools for Excel", , , , , , 1) If I < 1 Then MsgBox "incorrect enter", vbInformation, "Kutools for Excel" Exit Sub End If ReDim xOutArr(1 To I, 1 To Int(xRg.Rows.Count / I) + 1) For K = 0 To xRg.Rows.Count - 1 xOutArr(1 + (K Mod I), 1 + Int(K / I)) = xRg.Cells(K + 1) Next xOutRg.Range("A1").Resize(I, UBound(xOutArr, 2)) = xOutArr End Sub
3. Then press F5 key to run this code, and in the popped out box, please select the column that you want to split into multiple groups, see screenshot:
4. And click OK button, then select a cell where you want to locate the result in the following prompt box, see screenshot:
5. Click OK, and please enter the number of cells that you want to split per column in the prompt box, see screenshot:
6. Finally, click OK to finish the code, and the selected list data has been split into multiple equal groups as you need, see screenshot:
If you have installed Kutools for Excel, with its Transform Range feature, you can quickly split a long list into multiple columns and rows, moreover, you can also combine multiple columns into one long list.
|Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 30 days.|
After installing Kutools for Excel, please do as follows:
1. Select the long list that you want to split, and then click Kutools > Range > Transform Range, see screenshot:
2. In the Transform Range dialog box, select Single column to range under the Transform type section, and then check Fixed value and specify the number of cells per row in the box, see screenshot:
3. Then click Ok, and select a cell where you want to locate the result in the prompt box, see screenshot:
4. And click OK button, the data in the list has been split into multiple equal groups as you need.