Avatar of Jagwarman
 asked on

Random distribution formula

is there a formula that will divide a number randomly between a given number.      
So lets say I have 10 clients and 35 widgets.      
I want to distribute the widgets across the 10 clients randomly.      
Client 1      gets 4
Client 2      gets 0
Client 3      gets 3
Client 4      gets 2
Client 5      gets 1
Client 6      gets 1
Client 7      gets 3
Client 8      gets 6
Client 9      gets 8
Client 10      gets 7

Thanks in advance
Microsoft ExcelVBA

Avatar of undefined
Last Comment
Rob Henson

8/22/2022 - Mon
Ryan Chong

try this..

thanks Ryan only this is I was looking for formula rather than vba. The above was an example and so potentially the number of Clients will be a moving target. i.e. I put 10 in example but in live there could be 20 or 70 or 35 or 100 etc.

Ryan Chong

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question


Or you could use a UDF returning an array see example

Function RandomWidgets(nrWidgets) As Variant
Dim Res() As Integer
    With Application.Caller
        CallerRows = .Rows.Count
    End With
    ReDim Res(0 To CallerRows - 1)
    For i = 1 To nrWidgets
        rIdx = Rnd * Now() Mod CallerRows
        Res(rIdx) = Res(rIdx) + 1
    RandomWidgets = Application.Transpose(Res)

End Function

Open in new window

Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy

I like that and it's flexible
Rob Henson

Fomula driven, for first client, in G4:

=RANDBETWEEN(0,B1)   where B1 has number of widgets

For remaining clients G5 down, against list created manually in column A:


Checks if last client and takes balancing figure other wise takes Random value between remainder and zero.

Rob H