打开开发者模式,添加按钮,文本框1,文本框2,按钮上右键制定宏jiafa
Sub jiafa()
Randomize '必要代码,不然的话每次随机生成都是一样的数
n = ActiveSheet.TextBox1.Value '表示随机最小值,自己加文本框或替换成数字
m = ActiveSheet.TextBox2.Value '表示随机最大值,
If m < n Then
Exit Sub
End If
i = 1
For y = 1 To 15 '生成的列数
For x = 1 To 30 '生成的行数
i = 1
Do
a = Int(Rnd * (m - n + 1)) + n
b = Int(Rnd * (m - n + 1)) + n
c = a + b
If c < m Then
Cells(x, y).Value = a & "+" & b & "="
i = i + 1
End If
If i = 2 Then
Exit Do
End If
Loop
Next
y = y + 2
Next
End Sub