How to generate all possible combination of words from set of letters to solve Anagram?
If you don’t want to get too much into technical details of this Word Combination Generator for Anagram, follow these steps:
- Create an excel and design the Sheet 1 fields as in the image
- Copy Paste the Code into VB Editor (Press Alt F11 from Excel sheet to view the VB Editor)
- Execute the code by pressing F5.
- Possible Words for Anagram will be created in Sheet 2.
- Copy all rows in Sheet 2 to a notepad and remove the Spaces or Tabs to use the words.
Not all the words generated by this excel will be meaningful. It just gives us all possible permutations that can be formed using the letters given as input.
Is this only a Anagram Solver?
This Excel could come handy in many other ways, some of them are explained in scenarios listed below.
- Name Combination: Many of us should have heard, at least once, some Kid’s Names that combine the name of their parents. It would have been a fun experience for their parents to write down all possible meaningful words and choose the best from the list of names. Equally there are chances they might have missed some simple nice word.
- Puzzles: This excel application can also be used to jumble the alphabets of a meaningful word for any quiz program or anagram related questions.
- Password generator: If we have to periodically change system password or any internet/computer application Login password.
- Beware – Old hackers might use it too: This is also a very simple prototype of Brute Force Search, which can generate all possible words to crack password.
Also Read: How to Password Protect Excel 2010 & 2007?
Let’s make it more fun and creative, by making the excel to generate all possible word combinations.
An example excel macro code is presented in this article that implements simplified version of this algorithm. But here it has a limitation of maximum 8 characters as input.
Work Sheet Design:
When this code is executed, it first takes each letter,one at a time and place them in all possible position for each permutation or combination.
Visual Basic12345678910111213141516171819202122232425262728293031323334353637383940414243444546Private Sub Generate_Alphabet_Combination()''''''''''''' Add a Sheet for OutputSheets.Add , ThisWorkbook.Sheets(1)ThisWorkbook.Sheets(2).Activate''''''''''''' Declare VariabesDim Count_Of_Alphabets As DoubleDim Possible_Words As DoubleCount_Of_Alphabets = 1''''''''''''' Calculate The PermutationsWhile ThisWorkbook.Sheets(1).Cells(1, Count_Of_Alphabets) <> ""Count_Of_Alphabets = Count_Of_Alphabets + 1WendCount_Of_Alphabets = Count_Of_Alphabets - 1ThisWorkbook.Sheets(1).Cells(3, 17) = Count_Of_AlphabetsThisWorkbook.Sheets(1).Cells(4, 17) = "=fact(q3)"Possible_Words = ThisWorkbook.Sheets(1).Cells(4, 17)''''''''''''' Actual Code for Combination Processn = Possible_Wordsn1 = Count_Of_AlphabetsFor Current_Alphabet = 1 To Count_Of_Alphabetsn = n / n1Destination_Column = 1i1 = 0For Destination_Row = 1 To Possible_WordsWhile i1 = n Or ThisWorkbook.Sheets(2).Cells(Destination_Row, Destination_Column) <> ""Destination_Column = Destination_Column + 1i1 = 0If Destination_Column > Count_Of_Alphabets ThenDestination_Column = 1End IfWendThisWorkbook.Sheets(2).Cells(Destination_Row, Destination_Column).SelectThisWorkbook.Sheets(2).Cells(Destination_Row, Destination_Column) = ThisWorkbook.Sheets(1).Cells(1, Current_Alphabet)i1 = i1 + 1Next Destination_Rown1 = n1 - 1Next Current_Alphabet''''''''''''' Information sectionThisWorkbook.Sheets(1).Cells(10, 17) = "Http://OfficeTricks.com"End Sub
The actual combination generation loop starts after the comment “Actual Code for Combination Process”. Running the code in debug mode (F8), will reveal the actual logic implemented.
Also Read: Excel Mind Game -2048 Game – Free Download
- 1) word
- 2) wodr
- 3) wrod
- . . . . .
- 24) rdow
I hope you enjoyed trying this simplest version of Word Combination Generator. Leave your comments or suggestions if you liked it.
- Brute Force: http://en.wikipedia.org/wiki/Brute-force_search
- Anagram: http://en.wikipedia.org/wiki/Anagram
Previous Post: Excel Date Format Conversion – Number Format Changes
Next Post: Excel VBA AutoFilter Multiple Criteria in Array or List
Word Combination Generator – Anagram Guide