|
Option Explicit
Sub test2()
Dim ar, vTemp, i&, j&, r&, n&, iRnd&, d
Application.ScreenUpdating = False
ar = [F8:U23].Value
vTemp = Application.Index(ar, UBound(ar))
vTemp(UBound(vTemp)) = Empty
For j = 1 To UBound(ar, 2) - 1
vTemp(UBound(vTemp)) = vTemp(UBound(vTemp)) + ar(UBound(ar, 2), j)
Next j
For i = 1 To UBound(ar) - 1
n = ar(i, UBound(ar, 2))
For j = 1 To UBound(ar, 2) - 1
ar(i, j) = Int(vTemp(j) / vTemp(UBound(vTemp)) * ar(i, UBound(ar, 2)))
n = n - ar(i, j)
Next j
Do Until n = 0
iRnd = Int((UBound(vTemp) - 1) * Rnd + 1)
If ar(i, iRnd) + 1 <= vTemp(iRnd) Then
ar(i, iRnd) = ar(i, iRnd) + 1
n = n - 1
End If
Loop
For j = 1 To UBound(vTemp)
vTemp(j) = vTemp(j) - ar(i, j)
Next j
Next i
[F8].Resize(UBound(ar) - 1, UBound(ar, 2) - 1) = ar
Application.ScreenUpdating = True
Beep
End Sub
|
|