我试图总结超过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
答案 0 :(得分:4)
我对VBA了解不多,但可以
Cells(x, y).Value = Int(Rnd * rand)
If (ActiveCell.Value >= 500) Then
..指的是不同的细胞?