Here's a formula solution, based on John Topley's logic:

In A4, enter

=IF(A2<=$A$6-SUM(B4:$Z4),A2,0)

And copy to B4:Y4. Enter the sum of the values into A6, and the numbers that sum to that value will be shown in row 4.