|
Option Explicit
Sub TEST2()
Dim ar, br, i&, j&, vTemp, t#
Application.ScreenUpdating = False
t = Timer
br = RndNumCount(1, 9, 9)
ReDim ar(1 To 9, 1 To 9)
For i = 1 To UBound(ar)
ar(i, 1) = br(i)
vTemp = ar(i, 1)
For j = 1 To 8
vTemp = ar(i, 1) + j
ar(i, j + 1) = IIf(vTemp Mod 9 = 0, 9, vTemp Mod 9)
Next j
Next i
[A1].Resize(9, 9) = ar
Application.ScreenUpdating = True
MsgBox "执行完毕!_用时: " & Format(Timer - t, "0.0000") & " 秒", 64
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
|
评分
-
1
查看全部评分
-
|