|
如何能用一段代码实现将一个总数分解成若干个随机生成的数?
- Sub Macro1()
- Dim arr(1 To 50, 1 To 1), i%, n%
- Range("f3:j100").ClearContents
- For i = 1 To 5
- line1:
- s = 0: n = 0: x = 100
- Do While s < x
- y = Application.Round(Rnd * 6 + 2, 2)
- s = s + y
- n = n + 1
- arr(n, 1) = y
- If s >= 92 Then Exit Do
- Loop
- If x - s < 2 Then GoTo line1
- arr(n + 1, 1) = x - s
- Cells(3, i + 5).Resize(n + 1) = arr
- Erase arr
- Next
- End Sub
复制代码
|
|