Anagram on Excel

Solved
dmxs291 Posted messages 13 Status Member -  
dmxs291 Posted messages 13 Status Member -

Good evening, I would like to know if we can input a series of letters in Excel and display all possible anagrams, whether they make sense or not. If so, please provide me with the procedure to follow. Thank you!

6 answers

  1. Frenchie83 Posted messages 2254 Status Member 339
     
    Hello
    This is a recurring topic that has had many responses. Very competent contributors on this site will be able to offer you some very effective solutions, but in the meantime, I can modestly suggest a solution (which, from a programming perspective, is not the most efficient, but it has the merit of working).
    Enter the characters to be permuted in A1 (maximum 12 characters), then click the button. It is obvious that the more characters there are, the longer the search time for permutations will be.
    In the meantime, try better proposals.
    https://www.cjoint.com/c/CIishRLh5pr
    Have a good evening
    Best regards
    2
    1. Raymond PENTIER Posted messages 58213 Registration date   Status Contributor Last intervention   17 482
       
      ... with macro, as announced in my three messages.
      0
    2. Frenchie83 Posted messages 2254 Status Member 339
       
      Good evening Raymond
      Yes, of course with macro. In Excel, it might be feasible, but complicated to implement.
      Raymond, I saw in previous posts that you don’t practice VBA, but given your mastery of Excel and without wanting to flatter you, I have no doubt that you would provide practical solutions to problems that can only be solved by VBA.
      So Raymond, when will you start with VBA?
      Warm regards
      0
    3. Raymond PENTIER Posted messages 58213 Registration date   Status Contributor Last intervention   17 482
       
      All my neurons are occupied and saturated; I don't have enough left to tackle a new activity; and VBA is really one of those!
      As much as I was a fan of Basic back in the DOS days, I've never really got on with Visual Basic, despite various attempts.
      But thank you for your attention!
      0
  2. Raymond PENTIER Posted messages 58213 Registration date   Status Contributor Last intervention   17 482
     
    Hello.

    If we can? With a macro written in VBA, perhaps...

    With traditional methods, I'm afraid there's no other way than the one you're using with paper and pencil!
    Excel can then only help you
    1) to calculate the number of possible results, namely
    =PERMUTATION(LEN(A1),LEN(A1))
    and if A1 contains "zut" the result of the calculation is 6 (that is, zut-ztu-utz-uzt-tzu-tuz)
    But if A1 contains "cinq" there are already 24 possibilities; if A1 contains "douze" there are 120 solutions... and when we get to "cordialement" there are 479,001,600 anagrams to find!
    2) just to write all of this neatly

    Retirement is great! Especially in the Caribbean... :-)
    ☻ Raymond ♂
    1
  3. ccm81 Posted messages 11033 Status Member 2 434
     
    Hello everyone

    With my old Excel 2003 I can't open the file from frenchie83 ....
    Another suggestion might be different but still VBA
    https://www.cjoint.com/?3IitOSd1E7H

    Have a good end of the day ... and good afternoon to Raymond (the lucky one)
    1
    1. Frenchie83 Posted messages 2254 Status Member 339
       
      Good evening ccm81
      For the pleasure of sharing
      Here it is in version 2000, first of all, I must point out that my work is more of a hack, so it can't be compared to your professional work, but it works. As for the presentation, it is different since I put each permutation result in the same cell, which allows me to fill several columns in cases where the number of characters to process results in a number exceeding the maximum number of rows.
      For the functionality, in A1, you put the characters to be permuted without any separator, then you click the button.
      One day when I have time, I will enjoy redoing it.
      Have a good evening
      0
  4. dmxs291 Posted messages 13 Status Member
     
    That's exactly what I want to do with Excel, but I'm not used to using it, so I don't understand much. I just want to program Excel in such a way that if I type a word, it gives me a list of all possible anagrams.
    0
  5. Raymond PENTIER Posted messages 58213 Registration date   Status Contributor Last intervention   17 482
     
    I believe you haven't read (or understood) what I wrote ... so let me summarize:
    Almost impossible ...
    ... unless you know VBA language, to create a macro.

    --
    Retirement is nice! Especially in the Caribbean ... :-)
    ☻ Raymond ♂
    0
    1. Raymond PENTIER Posted messages 58213 Registration date   Status Contributor Last intervention   17 482
       
      This request has already been made in the forum, and as far as I remember, no one was able to propose a classical solution.
      0
    2. dmxs291 Posted messages 13 Status Member
       
      Alright, I see, well thanks anyway!
      0
  6. JvDo Posted messages 1924 Registration date   Status Member Last intervention   859
     
    Good evening everyone,

    It is entirely possible to solve your problem without using VBA.

    All it "takes" is generating the permutations in lexicographic order by starting, for example, from a Kivabian algorithm (the one I used comes from the book by Berstel, Pin, and Pocchiola: Mathematics and Computer Science) and transposing it into Excel/spreadsheet.

    Naturally, anything combinatorial escalates quickly, and the number of anagrams becomes unmanageable.
    So, I limited the number of letters to 8 (still 40,320 permutations).

    Then, I worked on the indices (from 1 to 8) to list the permutations from 12345678 to 87654321.
    From there, it is enough to use the INDEX() function to obtain the alphabetical equivalent of the permutations.

    However, the formulas are not simple as they perform the work of an algorithm.
    Here is a workbook https://www.cjoint.com/c/CIjbU1S01km that lists the anagrams of an 8-letter word.
    For size reasons, I only kept the first 40 rows. You will need to copy down (up to 40322) to have a complete table.

    You will need to modify it a bit for it to work with words of shorter lengths.

    Best regards.
    0
    1. Raymond PENTIER Posted messages 58213 Registration date   Status Contributor Last intervention   17 482
       
      Well done!
      dmxs291 will be able to take care of ...
      0
    2. ccm81 Posted messages 11033 Status Member 2 434
       
      Could you upload your spreadsheet in Excel 2003 format? I'm curious to see the "beast."
      Thank you.
      0
    3. JvDo Posted messages 1924 Registration date   Status Member Last intervention   859
       
      Hello ccm81,

      I had to revise my formulas to make them compatible with the 97/2003 version (too many levels of nesting).
      I still get error messages when I change the format upon saving, but I don't see any issues when I open the generated xls file.
      It's up to you to let me know if it works for you.

      I've added comments to make the formulas understandable.

      Best regards

      https://www.cjoint.com/?CIjo4ccNeVI
      0
    4. ccm81 Posted messages 11033 Status Member 2 434
       
      Hello JvDo

      Thank you for adapting (and sending) the file in 2003 format
      It's really nice of you to take the time to explain the process
      I have no errors, neither on opening, nor after a F9, nor on saving, so everything is fine on that side
      I just have to dig into it, and apparently, there's quite a bit of work to do!

      Have a great end of your day

      Best regards
      0
    5. dmxs291 Posted messages 13 Status Member
       
      Thank you to all the speakers, I found what I was looking for, you are really little geniuses, thanks again and have a great day!
      0