我试图总结所有超过 500 的随机整数值,然后将它们显示在一个文本框中,但是它不起作用,并且每当我运行代码时,它的总和为零。这是使用 VBA 的用户表单内部。任何建议,将不胜感激。
Private Sub CommandButton1_Click()
Dim r As Double, c As Double, rand As Double, y As Double, x As Double, i As Double
r = TextBox1.Value
c = TextBox2.Value
rand = TextBox3.Value
Rnd [5]
i = 0
For x = 1 To r
For y = 1 To c
Cells(x, y).Value = Int(Rnd * rand)
If (ActiveCell.Value >= 500) Then
i = i + ActiveCell.Value
Else ' do nothing
End If
Next y
Next x
Cells(r + 1, c).Value = "SUM"
Cells(r + 1, c + 1).Value = i
MsgBox (i)
End Sub
最佳答案
我对VBA了解不多,但可以
Cells(x, y).Value = Int(Rnd * rand)
If (ActiveCell.Value >= 500) Then
..指的是不同的细胞?
关于vba - 尝试添加随机整数的总和,VBA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16331949/