Grouping Numbers

meighkee

New Member
Joined
Sep 3, 2008
Messages
43
Greetings,

I need help with something I was tasked to do for work. I'm familiar enough with Excel to know this is possible, but not sure how to develop the formula. I have a list of items with prices that I want to group into 4 similar totals. For example, I may have 12 items (no particular order) that I want to divide up into 4 groups, each with a total cost somewhat close to the other groups. Excel will look at the list of cells with numbers, and change the order into 4 groups each with similar totals. I hope that makes sense.

Don't see an option to post an attachment, but have a simple example I can provide.

Any help greatly appreciated.

Thank You,
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
You could use the Solver for something like this. If you don't have the Solver installed, click File > Options > Add-ins > Excel Add-ins (on the bottom) > Go > check the Solver box > OK.

Now set up your sheet like this:

Excel 2012
ABCDEFGHIJ
1ProductPriceGroupGroup1Group2Group3Group4Difference
2Product 1110000
3Product 26800000
4Product 389
5Product 433
6Product 572
7Product 695
8Product 714
9Product 887
10Product 953
11Product 1099
12Product 1179
13Product 121
14Product 1312
15Product 1451
16Product 1550
17Product 1623
18Product 177
19Product 1825
20Product 1910
21Product 2090

<tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
E2=COUNTIF($C$2:$C$21,1)
F2=COUNTIF($C$2:$C$21,2)
G2=COUNTIF($C$2:$C$21,3)
H2=COUNTIF($C$2:$C$21,4)
E3=SUMIF($C$2:$C$21,1,$B$2:$B$21)
F3=SUMIF($C$2:$C$21,2,$B$2:$B$21)
G3=SUMIF($C$2:$C$21,3,$B$2:$B$21)
H3=SUMIF($C$2:$C$21,4,$B$2:$B$21)
J3=ABS(MAX(E3:H3)-MIN(E3:H3))

<tbody>
</tbody>

<tbody>
</tbody>



Go to the Data tab, click Solver, and set up the problem like this:

Set Objective: J3
To: Min
By Changing Variable cells: C2:C21
Subject to the Constraints:
C2:C21<=4
C2:C21=integer
C2:C21 >=1
E2:H2=5
Solving Method: Evolutionary

Click Solve. The values in C2:C21 will be which group each product should go in. You can probably figure out what all the values are: 5 is the number of items in each group, 4 is the number of groups, etc. The Solver will go through thousands of combinations, and the J3 formula calculates the difference between the largest group and the smallest group. When that is minimized, you have your "best" combination.

Hope this helps.
 
Last edited:
Upvote 0
Thanks very much Eric. Will take a day or two to put this into work. Greatly appreciate your timely response. Will let you know how it's working for me.
 
Upvote 0
You could use the Solver for something like this. If you don't have the Solver installed, click File > Options > Add-ins > Excel Add-ins (on the bottom) > Go > check the Solver box > OK.

Now set up your sheet like this:

Excel 2012
ABCDEFGHIJ
1ProductPriceGroupGroup1Group2Group3Group4Difference
2Product 1110000
3Product 26800000
4Product 389
5Product 433
6Product 572
7Product 695
8Product 714
9Product 887
10Product 953
11Product 1099
12Product 1179
13Product 121
14Product 1312
15Product 1451
16Product 1550
17Product 1623
18Product 177
19Product 1825
20Product 1910
21Product 2090

<tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
E2=COUNTIF($C$2:$C$21,1)
F2=COUNTIF($C$2:$C$21,2)
G2=COUNTIF($C$2:$C$21,3)
H2=COUNTIF($C$2:$C$21,4)
E3=SUMIF($C$2:$C$21,1,$B$2:$B$21)
F3=SUMIF($C$2:$C$21,2,$B$2:$B$21)
G3=SUMIF($C$2:$C$21,3,$B$2:$B$21)
H3=SUMIF($C$2:$C$21,4,$B$2:$B$21)
J3=ABS(MAX(E3:H3)-MIN(E3:H3))

<tbody>
</tbody>

<tbody>
</tbody>



Go to the Data tab, click Solver, and set up the problem like this:

Set Objective: J3
To: Min
By Changing Variable cells: C2:C21
Subject to the Constraints:
C2:C21<=4
C2:C21=integer
C2:C21 >=1
E2:H2=5
Solving Method: Evolutionary

Click Solve. The values in C2:C21 will be which group each product should go in. You can probably figure out what all the values are: 5 is the number of items in each group, 4 is the number of groups, etc. The Solver will go through thousands of combinations, and the J3 formula calculates the difference between the largest group and the smallest group. When that is minimized, you have your "best" combination.

Hope this helps.

Good Morning Eric,

When inputting the Solver data, the line - C2:C21=integer - is giving me the following error message when using the word integer as a constraint. "Constraint must be a number, simple reference, or formula with a numeric value." Should I actually be plugging in a cell location rather than using the word 'integer'?

Thanks much,
 
Upvote 0
You don't type the word integer. When you enter the constraint, you put the range in the left box, and there's a drop-down in the middle with the operator. Click the drop-down and select "int".
 
Upvote 0
You don't type the word integer. When you enter the constraint, you put the range in the left box, and there's a drop-down in the middle with the operator. Click the drop-down and select "int".

Can you give me an example of the range?
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,012
Members
449,204
Latest member
tungnmqn90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top