As I mentioned in the comment, the standard solver in Excel has a maximum limit for decision variables of 200.
This example is limited to 200 variables - if you have the premium solver, you can expand the solution. This was done using Excel 2016.
Worksheet setup
- Column A contains the size data.
- Column B contains the "Group" that each member in Column A will belong to. It is initially populated using the formula
=RANDBETWEEN(1,5)
. It was then overridden using Copy / Paste Special - Values.
- Column D contains the aggregated groups, labelled 1 through 5.
- Column E contains the aggregated size within each group. It is calculated with
=SUMIF($B$2:$B$201,"="&D2,$A$2:$A$201)
- Column F contains the target value for each group (1000 for groups 1 through 4, ignored for group 5).
- Column G contains the squared error from the target value for each group. It is calculated with
=(E2-F2)^2
- Cell G7 will be the "Set Objective" cell and is the sum of error squared. It is calculated with
=SUM(G2:G5)
Below is a screen shot of the setup worksheet, before using solver.

Solver Setup
Solver is setup with the following criteria ...
- "Set Objective:" is
$G$7
- "To:" is "Min"
- "By Changing Variable Cells:" is
$B$2:$B$201
- "Subject to the Constraints:" includes:
$B$2:$B$201 <= 5
, $B$2:$B$201 = integer
, and $B$2:$B$201 >= 1
- "Select a Solving Method:" is
Evolutionary
. Note: You could use GRG, but it will be much slower.
- In "Options", on the "All Methods" tab, in the "Solving with Integer Constraints" area, make sure
Ignore Integer Constraints
is not checked.
Below is a screen shot of the Solver Parameters dialog:

Solution
Your optimal region may be "flat" so there are multiple possible solutions.
Below is a screen shot of a solution I generated ...
