Combinação do Excel 6 [fechada]

0

Bom dia,

Estou tentando fazer no excel toda a combinação possível de 1 a 6 sem repetir.

6! Como posso listar as 720 possibilidades

Obrigado exemplos 123456 132456 654321

    
por Francisco 27.01.2015 / 18:31

1 resposta

2

Esta macro é simples, mas lenta:

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
    
por 27.01.2015 / 19:10