Thank you so much it's look fine. but is it not possible without macro? means with excel formula
It can be done by formula solution with helper columns, please see as per following :
1] Create Helper Column 1 &2, by : Select J2:I48 >> Copy and paste to "Helper 1 & Helper 2" >> L2:M48
2] Select "Helper 1" header cell L1 >> "Editing" >> "Sort &Filter" >> Choose : "Sort A to Z", in sorting Helper 1 column by ascending order >> OK
3] In "Helper 3" N2, formula copied down :
=IF(SUM(N$1:N1)+M2>Q$2,MAX(Q$2-SUM(N$1:N1),0),M2)
4] In "Allocation" I2, formula copied down :
=IFERROR(1/(1/INDEX(N:N,AGGREGATE(15,6,ROW($L$2:$L$48)/($L$2:$L$48=G2),COUNTIF(G$2:G2,G2)))),"")
5] Hide all helper columns as per your required
6] See attached file
Regards