香川群子 发表于 2014-4-15 21:58
没看明白你的意思。
请上附件。
谢谢老师回复我! 我引用的是老师在其他网站上发表过的一段代码。
draft.rar
(16.42 KB, 下载次数: 28)
- [quote]Dim sj, jg(), m%, n%, k
- Sub kagawa_Permut()
- tms = Timer
- m = [a1].End(4).Row
- sj = [a1].Resize(m)
- n = [b1]
- If n = 0 Or n > m Then n = m
-
- AP = WorksheetFunction.Permut(m, n)
- ReDim jg(AP, n)
- k = 0
-
- Call dgPL("", 0)
- MsgBox Format(Timer - tms, "0.000s")
- [b3] = AP
- If k < 65536 Then [d1].CurrentRegion = "": [d1].Resize(AP, n + 1) = jg
- End Sub
- Sub dgPL(s, t)
- If t = n Then
- p = Split(s, ",")
- For j = 1 To n
- ' jg(k, j) = sj(p(j), 1)
- ' jg(k, 0) = jg(k, 0) & "," & sj(p(j), 1)
- jg(k, 0) = jg(k, 0) & sj(p(j), 1)
- Next
- ' jg(k, 0) = Mid(jg(k, 0), 2)
- k = k + 1
- Exit Sub
- End If
- For j = 1 To m
- If InStr(s & ",", "," & j & ",") = 0 Then Call dgPL(s & "," & j, t + 1)
- Next j
- End Sub[/quote]
复制代码 |