|
楼主 |
发表于 2013-7-4 22:52
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
标准For……Next循环计算组合,组合结果也用Mid方法进行置换的话,速度也还是相当地快,
Combin(50,5)=2118760 只要0.28秒- Sub AutoCombin_Mid_5()
-
- tms = Timer
- Dim k&, l&, m&, n&, s$
- n = 5: m = [a1].End(4).Row
- 'AC = WorksheetFunction.Combin(m, n)
- 'ReDim jg(1 To AC, 0 To n)
-
- sj0 = [a1].Resize(m)
- For i = 1 To m
- If Len(sj0(i, 1)) > l Then l = Len(sj0(i, 1))
- Next
- s = String(l, " ")
- ReDim sj$(1 To m)
- For i = 1 To m
- sj(i) = Right(s & sj0(i, 1), l)
- Next
- s = ""
- For i = 1 To n
- s = s & sj(i)
- Next
-
- Dim i1%, i2%, i3%, i4%, i5%
- For i1 = 1 To m - 4
- Mid(s, 1, l) = sj(i1)
- For i2 = i1 + 1 To m - 3
- Mid(s, l * 1 + 1, l) = sj(i2)
- For i3 = i2 + 1 To m - 2
- Mid(s, l * 2 + 1, l) = sj(i3)
- For i4 = i3 + 1 To m - 1
- Mid(s, l * 3 + 1, l) = sj(i4)
- For i5 = i4 + 1 To m - 0
- Mid(s, l * 4 + 1, l) = sj(i5)
- k = k + 1
- ' jg(k, 0) = s
- Next i5, i4, i3, i2, i1
- MsgBox k & vbCr & Format(Timer - tms, "0.000s")
-
- End Sub
复制代码 |
|