关于EXCEL随机取数函数

来源:百度知道 编辑:UC知道 时间:2024/05/16 14:15:03
一个月30天累加起来等于90.46,每天可以用随机取数,怎么才会把30天累加起来刚刚好等于90.46呢,请指教!

a1到a29
=rand()*4
a30
=90.46-sum(a1:a29)

我来拿分……
打开excel表格,在B33处输入 =SUM(B1:B30)
进入VB 编辑器,新建模块,在模块粘贴以下代码:

Sub test()
Dim i As Integer
For i = 1 To 30
Sheet1.Cells(i, 2) = Int(Rnd() * 600)
Next i

Do While Range("B33").Value <> 9046
For i = 1 To 30
Sheet1.Cells(i, 2) = Int(Rnd() * 600)
Next i
Loop
For i = 1 To 30
Cells(i, "B") = Cells(i, "B") / 100
Next i
End Sub

执行宏,稍等,可得到希望看到的结果……