|
Dim isFlag As Boolean
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Sub 开始()
Dim ar, br, n&
With Worksheets(2).[A1].CurrentRegion
ar = Intersect(.Offset(), .Offset(1)).Value
End With
With Worksheets(1)
.Activate
n = .[B4].Value: isFlag = True
ReDim br(1 To n, 1 To UBound(ar, 2))
Range("d4:J33").ClearContents
Do
cr = RndNumCount(1, UBound(ar), n)
For i = 1 To UBound(cr)
For j = 1 To UBound(br, 2)
br(i, j) = ar(cr(i), j)
Next j
Next i
.Range("D4").Resize(UBound(br), UBound(br, 2)) = br
Sleep 100
DoEvents
Loop While isFlag = True
End With
End Sub
Sub 停止()
isFlag = False
End Sub
Sub 清除()
Range("d4:J33").ClearContents
End Sub
Function RndNumCount(MinNum&, MaxNum&, CountNum&)
Dim i&, n&, ar, xNum&, temp&
Application.Volatile
If MaxNum < MinNum Then temp = MaxNum: MaxNum = MinNum: MinNum = temp
If CountNum > MaxNum - MinNum + 1 Then RndNumCount = "无解": Exit Function
ReDim ar(1 To CountNum): n = 1
Randomize
Do While n <= CountNum
xNum = Int((MaxNum - MinNum + 1) * Rnd + MinNum)
ar(n) = xNum
For i = 1 To n
If ar(i) = xNum Then Exit For
Next i
If i = n Then n = n + 1
Loop
RndNumCount = ar
End Function
|
|