You decide how many groups you want by selecting a cell range with as many columns as you want groups and then enter the UDF. It is designed to group values depending on how many columns you have selected before entering it.
The animated picture above shows you a cell range with 5 columns.
This post shows you how to categorize values into worksheets:
Function GroupValues(rng As Range)
Dim result As Variant
c = Application.Caller.Columns.Count
r = Application.Caller.Rows.Count
ReDim result(1 To r, 1 To c)
i = 1
For ro = 1 To r
For co = 1 To c
If rng.Cells(i) <> "" Then
result(ro, co) = rng.Cells(i)
result(ro, co) = ""
i = i + 1
GroupValues = result
How do I copy the code to my workbook?
Open VB editor (Alt+F11)
Insert a module to your workbook
Paste code to code module
Go back to Excel
Note, make sure you save your workbook as a *.xlsm file or your workbook will lose all your vba code next time you close it.