|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
'就是求组合,而不是求排列,一般是用递归比较方便,给个示例供参考:
Dim path, res, m&, n&, k&, cnt&
Sub test()
k = 0: m = 10: n = 3 '10取3,可修改m,n的值获取不同组合
ReDim path(1 To n)
ReDim res(1 To WorksheetFunction.Combin(m, n), 1 To n)
combine 1: Range("A1").Resize(UBound(res), n) = res
End Sub
Sub combine(startindex)
Dim i&, j&
If cnt = n Then
k = k + 1
For j = 1 To n
res(k, j) = path(j)
Next
Exit Sub
End If
For i = startindex To m - (n - cnt) + 1
cnt = cnt + 1
path(cnt) = i
combine i + 1
cnt = cnt - 1
Next
End Sub
|
评分
-
1
查看全部评分
-
|