'Dividing vector into groups by another vector

I have the following table (for example, the real table is 100 rows):
It has a group name column, n students in group, and score.
It has a group name column, n students in group, and score.

I would like to build a forth column of cluster, which will divide the groups into 10 decimils of approximatly equal size, while preserving the score. So if i have a total number of 80 students in all groups together, than I'll have 10 clusters which have about 8 students each one more or less. the top cluster will consist the groups with the highest grade. I hope it makes any sense. My problem is more an algorithmic one, I prefer to have a solution in excel/vba other than R just because I need a more dinamic solution. I tried to do it manually by sorting the groups by score, and then summing the n of students until i get a number close to the decimil of the total number of students, but maybe there is an algorithem more precise and less frustrating than that.

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source