VBA Descrambling Words

Stephen_IV

Well-known Member
Joined
Mar 17, 2003
Messages
1,171
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Good morning. I have a list of Presidents that I have have on Sheet2 i.e.
WASHINGTON
LINCOLN
KENNEDY

On sheet1 I have scrambled the presidents i.e for WASHINGTON I could have TNSHWOINGA or GNOWNIHSA or WISOTGHNNA exc. Is there a way to descramble the the words on Sheet1 with a function that will match the list on Sheet2? So for instance if I had TNSHWOINGA it would bring back WASHINGTON. All of the names will be distinct. Thanks in advance
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I have a worksheet that uses a common permutation code, a spellcheck code, and sort code to unscramble words.

Huge drawback is that it iterates each combination of the scrambled letters with the following length/combinations.

3 - 6
4 - 24
5 - 120
6 - 720
7 - 5040
8 - 40320
9 - 362880
10 - BUST over one million

So Taft, Bush, Davis scrambles are almost blink fast. Jefferson is a "few" minutes, maybe not that long, and Washington will not play because it is over a million rows.
The permutation goes fairly fast, but the spell check labors along, then a quick sort to rid all misspelled combinations.
Not sure if there are other codes that will do the job any faster or able to handle over a million rows.

Howard
 
Upvote 0
I also have a program that does permutations and sends the permutations to the Excel Spell Checker. But as Howard said, the number of permutations grows rapidly, and if the words aren't in the spell checker, like proper names, then it won't work.

So I took a different approach. If you already have a list of the unscrambled words, and it's just a matter of finding the matching word, then we can do it with a "simple" formula.

For example:

ABC
1WordsMatch
2TNSHWOINGAWASHINGTON
3GNOWNIHSA#N/A
4WISOTGHNNAWASHINGTON
5COLNLINLINCOLN
6colnlinLINCOLN
7dorfFord
8jackonsJackson
90

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet1

Worksheet Formulas
CellFormula
C2=LOOKUP(2,1/(MMULT((LEN(A2)-LEN(SUBSTITUTE(UPPER(A2),CHAR(COLUMN(INDIRECT("A:Z"))+64),""))=LEN(Sheet2!$A$2:$A$10)-LEN(SUBSTITUTE(UPPER(Sheet2!$A$2:$A$10),CHAR(COLUMN(INDIRECT("A:Z"))+64),"")))+0,ROW(INDIRECT("1:26"))^0)=26),Sheet2!$A$2:$A$10)

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>



The way it works is by compiling a list of how many As, Bs, Cs, etc. are in the scrambled word. Then finding out how many As, Bs, Cs, etc. are in each of the reference words. If we get a match where every letter has the same count, then we've found the word.
 
Upvote 0
Eric,

Thank you very much! That seems to do the job and is exactly what I am looking for! I appreciate your health and time! Thanks again!
 
Upvote 0
@ Eric

Pretty darn slick!!

Maybe obvious to others, but I note the lists scrambled vs unscrambled do not have to correspond row to row, i.e. DORF as second entry scrambled list will find FORD as sixth entry on unscrambled list.

Thanks for the formula.

Howard
 
Upvote 0

Forum statistics

Threads
1,216,081
Messages
6,128,695
Members
449,464
Latest member
againofsoul

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top