|
楼主 |
发表于 2024-5-5 14:57
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
老师好,如果想要按5个数排组合,是不是把下面的K=3改成K=5 ,这样可以吗?
Sub test()
Dim r&, i&, c&, j&, m&, n&, k&
Dim arr, brr(), crr()
With Worksheets("sheet1")
For Each y In Array(1, 12, 23)
r = .Cells(.Rows.count, y).End(xlUp).Row
arr = .Cells(1, y).Resize(r, 1)
k = 5
ReDim brr(1 To 2, 1 To k)
For j = 1 To UBound(brr, 2)
brr(1, j) = j
brr(2, j) = UBound(arr) - k + j
Next
s = Application.Combin(UBound(arr), k)
ReDim crr(1 To s, 1 To k)
For i = 1 To s
For j = 1 To UBound(brr, 2)
crr(i, j) = arr(brr(1, j), 1)
Next
For j = k To 1 Step -1
If brr(1, j) < brr(2, j) Then
brr(1, j) = brr(1, j) + 1
For q = j + 1 To k
brr(1, q) = brr(1, q - 1) + 1
Next
Exit For
End If
Next
Next
.Cells(1, y + 2).Resize(UBound(crr), UBound(crr, 2)) = crr
Next
End With
End Sub
|
|