Hi Gary
It's easy to generate words based on a list of letters. You just have to build the permutations and check spell them. The problem is that, as you may remember, the factorial grows very fast, even faster than the exponential. This means that it's not a practical method for a big number of letters.
You can use the code I post comfortably with until 7 letters (about 8 seconds). For 8 letters it takes already one minute. For 10 letters it would take 1 and a half hours.
If you really want to build a tool to do this efficiently for any number of letters, you must take a different approach. One simple solution is to get the words of the dictionary and build a list of the words by theirs letter combinations (not permutations). This will be done just once and then finding the words with 3 letters or 15 will be the same, surely less than a second.
I used excel's spell checker in this code, writes the results in column A:
Example:Code:Sub PermValidWords() Dim rRng As Range, lRow As Long, sStr As String Set rRng = Range("C1:F1") sStr = Join(Application.Index(rRng.Value, 1, 0), "") lRow = 1 Columns("A").Clear Call perm(sStr, "", lRow) End Sub Sub perm(sStr As String, sPerm As String, lRow As Long) For i = 1 To Len(sStr) Call perm(Mid(sStr, 1, i - 1) & Mid(sStr, i + 1, Len(sStr) - i), sPerm & Mid(sStr, i, 1), lRow) Next If sStr = "" Then If lRow = 1 Or IsError(Application.Match(sPerm, Range("A1:A" & lRow), 0)) Then If Application.CheckSpelling(sPerm) Then Range("A" & lRow) = sPerm lRow = lRow + 1 End If End If End If End Sub
* A B C D E F G 1 opts * o p t s * 2 pots * * * * * * 3 post * * * * * * 4 tops * * * * * * 5 spot * * * * * * 6 stop * * * * * * 7 * * * * * * * [Book1]Sheet2
Hope this helps
PGC


LinkBack URL
About LinkBacks



Reply With Quote

Bookmarks