Need to group rows until they reach a total and then group the next batch and so forth

thekaoboy

New Member
Joined
Sep 7, 2006
Messages
48
I have a long list of zip codes and a total units within each zip code. I want to create groups of zip codes where the totals add up to a certain number.

In the example table below, the zips and counts are in no particular order. But I want to start adding up the counts cumulatively until they reach the magic number of 43 and then that would represent Group A. Then start the cumulative count over again until the total reaches 43 and then that is Group B. And so forth. The Column marked "43" is a sample of my desired result.

Thanks all.

ZipCount43
305268Group A
3821213Group A
384308Group A
1347619Group B
787689Group B
701583Group B
6332110Group B
298006Group C
709091Group C
6477910Group C
8797616Group C
5790410Group C
8897919Group D
6049419Group D
703908Group E
1788215Group E
654151Group E
970334Group E
5763711Group E
4141118Group F
912398Group F
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Here is a way you can do it with a helper column.
Assuming that your data is in columns A and B, and the first row of data is in row 2, place these formulas in the following cells:
C2: =B2
D2: Group A
C3: =IF(C2+B3<=43,C2+B3,B3)
D3: =IF(C2+B3<=43,D2,"Group " & CHAR(CODE(RIGHT(D2,1))+1))

Then copy the formulas in C3:D3 down for all rows.
Note that this will only work up until "Group Z".
 
Upvote 0

Forum statistics

Threads
1,214,431
Messages
6,119,457
Members
448,898
Latest member
drewmorgan128

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