Random distribution formula

Jagwarman
Jagwarman used Ask the Experts™
on
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.      
      
so       
      
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Ryan ChongSoftware Team Lead

Commented:
try this..
28695867.xlsm

Author

Commented:
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.

Regards
Software Team Lead
Commented:
Ok, so you may customize this sample instead.
28695867-b.xlsm
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Top Expert 2016

Commented:
HI,

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)
    Randomize
    For i = 1 To nrWidgets
        rIdx = Rnd * Now() Mod CallerRows
        Res(rIdx) = Res(rIdx) + 1
    Next
    RandomWidgets = Application.Transpose(Res)

End Function

Open in new window

Regards
28695867V1.xlsm

Author

Commented:
I like that and it's flexible
Rob HensonFinance Analyst

Commented:
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:

=IF(A6="",$B$1-SUM(G$4:G4),RANDBETWEEN(0,$B$1-SUM(G$4:G4)))

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

Thanks
Rob H

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial