体彩22选5,选n注,要求每注的随机数不相同,求问红色部分not is nothing和range.find是什么意思。
下面是程序
Sub 体彩()
Dim n, i As Long, j As Long
Dim r As Long
Worksheets("体彩").Activate
n = Application.InputBox("请输入注数:", "体彩22选5", , , , , , 1)
If TypeName(n) = "Boolean" Then
Exit Sub
End If
Columns("A:F").Select
Selection.ClearContents
Range("A1").Select
If n >= 0 Then
For i = 1 To n
Cells(i, 1).Value = "第" & i & "注"
For j = 1 To 5
Randomize
r = Int(Rnd * 22) + 1 '产生1,22之间的随机数
'唯一性检查
Do While (Not Range(Cells(i, 1), Cells(i, 5)).Find(r) Is Nothing)
Randomize
r = Int(Rnd * 22) + 1
Loop
Cells(i, j).Value = r
Next
Next
End If
End Sub