|
楼主 |
发表于 2014-11-28 11:36
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
数组循环算法的代码实现:
解释略- Sub GetCombin_Arr() 'by kagawa 2014/11/28
- Dim i&, j&, k&, l&, m&, n&, p&, w$, tms#
- tms = Timer
-
- m = [a1].End(4).Row: sj = [a1].Resize(m)
- n = [b1]: If n > m Then n = m
- w = [b2]: p = [b3]
- [d1].CurrentRegion = ""
-
- ReDim jg(2 ^ m - 1, 2)
- For i = 1 To n - 1
- For j = j To k
- For l = jg(j, 2) + 1 To m
- k = k + 1: jg(k, 1) = i: jg(k, 2) = l
- If k > m Then jg(k, 0) = jg(j, 0) & w & sj(l, 1) Else jg(k, 0) = sj(l, 1)
- Next
- Next
- Next
- If p Then [d1].Resize(k + 1, 2) = jg
-
- ReDim jg2(WorksheetFunction.Combin(m, n), 1): i = 0
- For j = j To k
- For l = jg(j, 2) + 1 To m
- jg2(i, 0) = jg(j, 0) & w & sj(l, 1): jg2(i, 1) = n: i = i + 1
- Next
- Next
- [d1].Offset(p * (k + 1)).Resize(i, 2) = jg2
- [b5] = p * (k + 1) + UBound(jg2): [b6] = Format(Timer - tms, "0.000s")
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|