Say we want to make 10 numbers that sum to 100. In A1 enter:
=RANDBETWEEN(1,50)
and in A2 enter:
=IFERROR(RANDBETWEEN(1,100-SUM($A$1:A1)),0)
copy A2 down through A10:
EDIT#1:
To use a macro, try:
Sub randomality()
Dim ary(1 To 10) As Double, zum As Double
Dim i As Long
Randomize
zum = 0
For i = 1 To 10
ary(i) = Rnd
zum = zum + ary(i)
Next i
For i = 1 To 10
ary(i) = ary(i) / zum
Next i
With Application.WorksheetFunction
For i = 1 To 10
Cells(i, "D").Value = Round(100 * ary(i), 0)
Next i
Cells(10, "D").Value = 100 - .Sum(Range("D1:D9"))
End With
End Sub
This puts the values in D1 through D10
7
solved Generate n random numbers Summed upto 100 VBA [closed]