Olá Angelito,
Desculpe pelo atraso na resposta.
Por favor, tente o código abaixo: (Observe que o código não processa uma string com mais de 8 caracteres. Se você quiser aumentar o número, você pode alterar o número 8 de "If Len(xStr) >= 8 Then" no código para números maiores. No entanto, quanto maior o número, mais lento o programa seria.)
Sub GetString()
'Updateby Extendoffice
Dim xStr As String
Dim FRow As Long
Dim xScreen As Boolean
Dim Rg, xRg As Range
xScreen = Application.ScreenUpdating
Application.ScreenUpdating = False
Set xRg = Application.InputBox("Enter text to permute:", "Kutools for Excel", , , , , , 8)
xStr = ""
For Each Rg In xRg
xStr = xStr + Rg.Text
Next
If Len(xStr) < 2 Then Exit Sub
If Len(xStr) >= 8 Then
MsgBox "Too many permutations!", vbInformation, "Kutools for Excel"
Exit Sub
Else
ActiveSheet.Columns(1).Clear
FRow = 1
Call GetPermutation("", xStr, FRow)
End If
Application.ScreenUpdating = xScreen
End Sub
Sub GetPermutation(Str1 As String, Str2 As String, ByRef xRow As Long)
Dim i As Integer, xLen As Integer
xLen = Len(Str2)
If xLen < 2 Then
Range("A" & xRow) = Str1 & Str2
xRow = xRow + 1
Else
For i = 1 To xLen
Call GetPermutation(Str1 + Mid(Str2, i, 1), Left(Str2, i - 1) + Right(Str2, xLen - i), xRow)
Next
End If
End Sub
Espero que funcione para voce.
Amanda