How do I find every letter combination from words or chosen letter

B

bgntg

I would like to know if there is some way within MS Office that you can not
only calculate, but also display every letter combination within words or
chosen letters?
 
B

Bob I

Well that sorta fits the question, but the calculate part really gave me
a "left turn from the right lane", so to speak.
 
J

JoAnn Paules [MSFT MVP]

I'm telling you - Mary is a freakin' genius when it comes to deciphering
posts that seem to make absolutely no sense!
 
M

Michael Bednarek

I would like to know if there is some way within MS Office that you can not
only calculate, but also display every letter combination within words or
chosen letters?

See: <http://j-walk.com/ss/excel/tips/tip46.htm>.

Below is some VBA code derived from that. Note that the word Anagram will
yield 5040 permutations (7!).

Sub tGetPermutation()
Dim theWord As String
theWord = "Anagram"
Debug.Print "There are " & Factorial(Len(theWord)) & " permutations."
Call GetPermutation("", theWord)
End Sub

Function Factorial(n As Long) As Double
Dim y As Long
Factorial = n
For y = 2 To n - 1
Factorial = Factorial * y
Next y
End Function

Sub GetPermutation(x As String, y As String)
' from : <http://j-walk.com/ss/excel/tips/tip46.htm>
' The source of this algorithm is unknown
Dim i As Integer, j As Integer
j = Len(y)
If j < 2 Then
Debug.Print x & y
Else
For i = 1 To j
Call GetPermutation(x + Mid(y, i, 1), Left(y, i - 1) + Right(y, j - i))
Next i
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top