早上好,
我尝试在 Excel 中计算 1 到 6 的所有可能组合,且不重复。
6!我该如何列出这 720 种可能性
谢谢,例子 123456 132456 654321
答案1
这个宏很简单,但是很慢:
Sub Pickz()
Dim i As Long, j As Long, k As Long, l As Long, m As Long, n As Long
Dim Z As Long
Z = 1
For i = 1 To 6
For j = 1 To 6
For k = 1 To 6
For l = 1 To 6
For m = 1 To 6
For n = 1 To 6
If Zort(i, j, k, l, m, n) Then
Cells(Z, 1) = i & j & k & l & m & n
Z = Z + 1
End If
Next n
Next m
Next l
Next k
Next j
Next i
End Sub
Function Zort(i, j, k, l, m, n) As Boolean
Dim c As Collection
Set c = New Collection
Zort = True
On Error Resume Next
c.Add i, CStr(i)
c.Add j, CStr(j)
c.Add k, CStr(k)
c.Add l, CStr(l)
c.Add m, CStr(m)
c.Add n, CStr(n)
If Err.Number = 0 Then
Else
Zort = False
Err.Number = 0
End If
On Error GoTo 0
End Function