I have a list of folders in a excel sheet which gives the name of the folder and how many files are in each folder.

I would like to know if there is a way in which I can get excel to look at this list and sort it into groups that contain a set total number of files in each group, so for example, say I have 20 folder with a total of 200 file altogether and I want the folder sorted into a given number of groups so that each group has the same number of files (i.e divide the 20 folders into 5 groups with 40 files (or as close a possible) in each group.).