This routine from John Walkenback - GIVE CREDIT to
him
Dim CurrentRow
Sub GetString()
Dim InString As String
InString = InputBox("Enter text to permute:")
If Len(InString) < 2 Then Exit Sub
If Len(S) >= 8 Then
MsgBox "Too many permutations!"
Exit Sub
Else
ActiveSheet.Columns(1).Clear
CurrentRow = 1
Call GetPermutation("", InString)
End If
End Sub
Sub GetPermutation(x As String, y As String)
' The source of this algorithm is unknown
Dim i As Integer, j As Integer
j = Len(y)
If j < 2 Then
Cells(CurrentRow, 1) = x & y
CurrentRow = CurrentRow + 1
Else
For i = 1 To j
Call GetPermutation(x + Mid(y, i, 1), _
Left(y, i - 1) + Right(y, j - i))
Next
End If
End Sub
Thanks Ivan with the Permutations routine from John. Actually it has only one problem eg.
If I enter the number '6000' , it should return the following values '6000,0600,0060,0006' but it gives me 24 values like '6,0,600 etc. Its perfect if I enter a 4 digit number with no repeats eg 1234. I forgot to say that I only want to permute on 4 digit numbers only.
I can still use it because I can edit the results in the worksheet.
Thanks a lot.
regards.
You can always add routine to format it as;
Selection.NumberFormat = "0000"
Ivan