|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
这个方法比较另类,在运算量不大的情况下,可以用,因为调用了工作表函数,如果运算量大就算了
- Sub MainC()
- ar = [a1].CurrentRegion
- ar = Application.Transpose(ar)
- n = UBound(ar) '---总n个
- m = [e2] '---选m个
- GetBase ar, n, m
- End Sub
- Function GetBase(ar, n, m)
- Set obj = Application.WorksheetFunction
- k = obj.Combin(n, m)
- ReDim br(k * 100, 0)
- i = 0: k = 0
- Do
- x = obj.Base(i, 2, n)
- If Len(Replace(x, 0, "")) = m Then
- For j = 1 To n
- l = Mid(x, j, 1)
- If l = "1" Then
- br(k, 0) = br(k, 0) & "," & ar(j)
- End If
- Next
- br(k, 0) = Mid(br(k, 0), 2)
- k = k + 1
- End If
- i = i + 1
- Loop Until Len(x) > n
- [g:g].Clear
- [g1].Resize(k) = br
- End Function
复制代码 |
|