|
try this:
- Sub zz()
- Dim ar, a(), b, jjj, n%, t As Boolean, d As Object, nn%
- Set d = CreateObject("scripting.dictionary")
- ar = Range("e6:w" & [w65536].End(3).Row).Value
- For i = 1 To UBound(ar) Step 3
- ReDim a(1 To 2, 1 To 18)
- For j = 1 To UBound(a, 2)
- a(2, j) = Rnd(): a(1, j) = j
- Next
- For j = 1 To UBound(a, 2) - 1
- b = a(2, j)
- For jj = j + 1 To UBound(a, 2)
- If a(2, jj) < b Then t = True: jjj = jj: b = a(2, jj)
- Next
- If t Then
- t = False
- n = a(1, j): a(1, j) = a(1, jjj): a(1, jjj) = n:
- a(2, jjj) = a(2, j): a(2, j) = b
- End If
- Next
- For j = 1 To UBound(a, 2)
- If Not a(1, j) > ar(i, 19) Then ar(i, j) = 1 Else ar(i, j) = ""
- Next
- 1000
- d.RemoveAll: n = 0: j = 0: jjj = 0: nn = IIf(Int(ar(i + 1, 19)) < 2, Int(ar(i + 1, 19)), 2)
- Do
- If d.count > 16 Then GoTo 1000
- k = Application.WorksheetFunction.RandBetween(jjj, nn)
- j = j + 1: n = n + k
- d(j) = k
- Loop Until n > Int(ar(i + 1, 19)) - 2
- jj = j: m = n
- 2000
- j = jj: n = m
- Do
- If d.count > 18 Then GoTo 2000
- k = Application.WorksheetFunction.RandBetween(jjj, ar(i + 1, 19) - n)
- j = j + 1: n = n + k
- d(j) = k
- If d.count > 18 Then jjj = jjj + 1: GoTo 1000
- Loop Until n = Int(ar(i + 1, 19))
- If ar(i + 1, 19) > Int(ar(i + 1, 19)) Then
- j = Application.WorksheetFunction.RandBetween(0, d.count - 1)
- k = d.keys
- d(k(j)) = d(k(j)) + Round((ar(i + 1, 19) - Int(ar(i + 1, 19))), 1)
- End If
- For j = 1 To 18
- ar(i + 1, j) = 0
- Next
- For Each k In d.keys
- ar(i + 1, k) = d(k)
- Next
- Next
- [e6].Resize(UBound(ar), UBound(a, 2)).ClearContents
- [e6].Resize(UBound(ar), UBound(a, 2)) = ar
- End Sub
复制代码
|
|