试图添加随机整数,VBA的总和

我试图总结所有500以上的随机整数值,然后将它们呈现在文本框中,但它不工作,每当我运行代码时,它总和为零。 这是使用VBA的用户表单的内部。 任何build议,将不胜感激。

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 

..是指不同的细胞?