|
Private Sub Worksheet_Change(ByVal Target As Range)
Dim ar, br, i&, j&
If Target.Address <> "$B$23" Then Exit Sub
If Not IsNumeric(Target.Value) Then Exit Sub
If Target.Value >= 1 And Target.Value <= 252 Then
ReDim ar(1 To 10)
For i = 1 To UBound(ar)
ar(i) = i - 1
Next i
ar = combinArr1(ar, 5)
Application.EnableEvents = False
[H26].Resize(5) = Application.Transpose(ar(Target.Value))
Application.EnableEvents = True
End If
End Sub
Function combinArr1(ByVal ar, ByVal n&)
Dim br&(), cr, vResult, i&, j&, m&, iCount&, iGroup&, vTemp
m = UBound(ar)
iGroup = Application.Combin(m, n)
ReDim vResult(1 To iGroup)
ReDim br&(1 To n)
ReDim cr(1 To n)
If n = 1 Then
For i = 1 To iGroup
cr(1) = ar(i)
vResult(i) = cr
Next i
combinArr1 = vResult
Exit Function
End If
For j = 1 To n - 1: br(j) = j: Next
iCount = 0
Do
For i = br(n - 1) + 1 To m
br(n) = i
iCount = iCount + 1
For j = 1 To n
cr(j) = ar(br(j))
Next j
vResult(iCount) = cr
Next
If br(n - 1) < br(n) - 1 Then
br(n - 1) = br(n - 1) + 1
Else
For j = n - 2 To 1 Step -1
If br(j) <> br(j + 1) - 1 Then
vTemp = br(j) + 1: br(j) = vTemp: j = j + 1
Do Until j = n
br(j) = br(j - 1) + 1: j = j + 1
Loop
Exit For
End If
Next
End If
Loop Until iCount = iGroup
combinArr1 = vResult
End Function
|
评分
-
1
查看全部评分
-
|