|
本帖最后由 小花鹿 于 2019-1-1 19:23 编辑
这样可以吗:
Sub test1()
Dim ar, br, cr, i&, s, su&, d, n&, tm, k&, m&, ar1, t
t = Timer
Dim c&, r&, mx&, hezhi&
Set d = CreateObject("scripting.dictionary")
Randomize
c = 2
r = 1
mx = 290
hezhi = 444
ar1 = Range("b2:b291")
ReDim cr(1 To r, 1 To c)
Do
s = ""
ReDim ar(1 To mx)
ReDim br(1 To mx)
For i = 1 To mx
ar(i) = ar1(i, 1)
Next i
su = 0
For i = 1 To c - 1
n = Int(Rnd() * (mx - i + 1)) + i
su = su + ar(n)
s = s & "+" & ar(n)
tm = ar(n)
ar(n) = ar(i)
ar(i) = tm
Next i
For i = c To mx
If su + ar(i) = hezhi Then
s = s & "+" & ar(i)
Exit Do
End If
Next i
Loop Until su = hezhi
MsgBox s & "|" & Format(Timer - t, "0.00")
End Sub
|
|