Excel Word Search Generator

Debra at Contextures blogged about creating a word search puzzle while she nursed a hangover (although she won’t admit it). Creating a word search puzzle in Excel seemed like a fun exercise, so I set about doing it.

excel word search puzzle

It’s not even close to finished, I’m just throwing the first draft out there to see what sticks. I have some design considerations.

The puzzle dimensions are set in A1 and the word list starts in A2. If a word is too big, you get an (currently unhandled) error. Perhaps I should allow the user to set the minimum puzzle size, but compute the correct puzzle size based on the word list. I haven’t thought about that algorithm much, but I think I’d start with Longest Word / 0.8. That would have to increase based on the number of long words. The more long words, the larger the puzzle will have to be to accommodate them all.

As it is now, if a word is greater than 80% of the puzzle dimensions I force the direction to be diagonal. If I don’t, the rest of the words use the same direction as the first word. For example, if SUMPRODUCT goes horizontally from row 4, column 1, then the odds are pretty good that the next three words will have to be either horizontal right or horizontal left. The only way they wouldn’t be horizontal is if, by luck, they meshed with SUMPRODUCT.

Any cells that aren’t part of a word are filled with a random letter. I’d prefer to fill some spaces with partial words, like MPROD, to make the puzzles harder. That will make the code run longer and it will increase the chance that I accidentally make a duplicate. I’d have to avoid that for small words, say five characters or less, which I think would make the odds of a duplicate almost nothing.

You can download the zip file if you want to check it out. If you have thoughts on how you’d design the puzzle, leave a comment.

Posted in Uncategorized

15 thoughts on “Excel Word Search Generator

  1. You could only use letters that appear in the words to fill in the blank cells. This would make the puzzles slightly harder, and may randomly add partial words into the puzzle. It would however increase the chance of randomly duplicating short words within the puzzle.

  2. Re circling a found word: break the paper-an-pencil paradigm and just color the cells in…

  3. Fantastic – I will have great fun looking at your code!

    I tried it out with a list of 95 Harry Potter names (max length 22, grid size = 22/0.8 = 27). The puzzle seemed to generate quite well but I noticed that while two of the names (Justrin-Finchley and You-Know-Who) contained hyphens there was only one hyphen in the grid. So not all the words are always included in the list and there is no indication of which words have been included and which not.

    Which made me wonder how difficult it would be to enhance the code so that if you highlight any word in the list the corresponding entry in the grid is highlighted …

  4. Replying to my own challenge – all you would need to do would be to store the initial cell and the direction and have these available in a dictionary or lookup table. Then you need a routine to highlight N cells given any starting cell and a direction.

  5. OK, I get it. I put a counter in there so that after 1,000 iterations, it would stop. You’re list of words is too long for a 27×27 grid and it quits after it can’t find space for them all. This is a good data point for the algorithm to determine optimum grid size. I wonder how that online place does it. Brute force would take too long.


Posting code? Use <pre> tags for VBA and <code> tags for inline.

Leave a Reply

Your email address will not be published.