How to distribute a set of numbers proportionally across cells in a TABLE

Phantom1

New Member
Joined
Sep 26, 2018
Messages
12
Office Version
  1. 2016
Platform
  1. Windows
Hello friends.

I have a distribution problem that i encounter all the time and need to speed up the process with formulas or vba. Any help is highly appreciated.

Lets say that we have 19 companies (A,B ,... S) that each one supply us with a number of a specific item. (All items are the same and the numbers given may vary)
After we code the items (so only us know from which company each item was received), we need to mix the items and return to the companies same number they gave us, for testing.

My problem is how to distribute automatically the items (integers) near to their ratios so can add up to their total not only in rows but in columns also
I use the round function and then correct the numbers manually , but that requires a lot of effort and time.

I have already read a similar question in the forum but the answer does not work in my case. "How to distribute a set number proportionally across cells and still keeping the total at set number" by Delta21

Some things to keep in mind of secondary importance are.
1. No company gets back for testing more than 10% of its own items
2. The maximum number of items someone gets back for testing from a company, appears at least twice so he cannot trace back the written code on an item to its original location.

I give a sample image of a finished problem.

Thanks in advance
 

Attachments

  • table.PNG
    table.PNG
    35.9 KB · Views: 89

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
For 2021 and 365
Every item gets a number, for the moment no check fo the % returned to the original supplier, but that's not a big deal.
VBA Code:
Sub Distribution()
     Dim b(), rand()
     Set lo = Sheets("blad1").ListObjects("Tbl_Suppliers")
     a = lo.DataBodyRange.Columns(2).Value
     som = Application.Sum(a)
     ReDim b(1 To UBound(a), 1 To 1)
     rand = Application.Transpose(WorksheetFunction.RandArray(som))
     For i = 1 To UBound(a)
          s = ""
          If a(i, 1) > 0 Then
               For j = ptr + 1 To ptr + a(i, 1)

                    s = s & ", " & Application.Match(WorksheetFunction.Small(rand, j), rand, 0)
               Next
          End If
          ptr = ptr + a(i, 1)
          If Len(s) > 0 Then b(i, 1) = "'" & Mid(s, 3)
     Next
     With lo.DataBodyRange.Columns(3)
          .Value = b
          .EntireColumn.AutoFit
     End With
End Sub
Map2
ABC
1CompanynumberKolom1
2A550, 4, 28, 54, 26
3B574, 34, 11, 73, 20
4C352, 33, 77
5D125
6E269, 55
7F558, 43, 78, 68, 1
8G276, 72
9H170
10I545, 23, 47, 49, 22
11J559, 71, 18, 12, 38
12K43, 37, 15, 6
13L421, 10, 57, 66
14M22, 61
15N360, 39, 19
16O124
17P263, 5
18Q151
19R465, 48, 14, 32
20S467, 53, 16, 64
21T317, 80, 56
22U38, 27, 75
23V131
24W362, 30, 42
25X513, 9, 41, 36, 40
26Y529, 79, 35, 44, 7
27Z146
Blad1
 
Last edited:
Upvote 0
This isn't clear
The maximum number of items someone gets back for testing from a company, appears at least twice so he cannot trace back the written code on an item to its original location
Can you please give an example?
 
Upvote 0
in attachment your 19 suppliers, difficult/impossible for max 10% own parts.
At the right handside, the distribution in detail
example file
 
Upvote 0
This isn't clear
The maximum number of items someone gets back for testing from a company, appears at least twice so he cannot trace back the written code on an item to its original location
Can you please give an example?
Thank you for taking the time to work on my problem.
Lets say that Company D is the major company that provides us with most of the items. Everybody knows that and all can see the code we write on an item.
If we sent to a third company for testing 100 items from company D and 20 from other companies then they will find out that the max number of 100 items with the same code corresponds to the larger company D.
But if we gave the third company another code with 100 items they could not be sure for our codes.
 
Upvote 0
Than
And your excel version is 2021 or 365 ?
Thanks for big effort and time spent. I am studying your file and trying to understand your coding. I will let you know.
I am working on Office 2016 Professional Plus
 
Upvote 0
Thanks BSALV.
Seems ok but couldn't make the code to run . Perhaps of my excel version (Office 2016 Professional Plus)
Doesn't bother if we enter manually number of own parts. we could use formula rounddown(ItemsOfCompany*10%,0)
1642449028348.png

I also notice that the first column doesn't add up to the total items given for company A.
 
Upvote 0
I am working on Office 2016 Professional Plus

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0

Forum statistics

Threads
1,215,344
Messages
6,124,407
Members
449,157
Latest member
mytux

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