Graphic representing this web site

clarcana.info: Projects:

SudokEx
🦢

A graphic denoting the subject of this page.

About SudokEx

SudokEx is a collection of routines written in Visual Basic for Applications (VBA) and which can be used with Excel to help solve the type of puzzle called Sudoku.

VBA is used only to initialise the spreadsheet cell values and formatting. That accomplished, the VBA macros become redundant and the resultant sheet may be stored in .xlsx format and opened by any spreadsheet application with near complete support for Excel conditional formatting (which currently excludes Numbers and Google Sheets ).

SudokEx highlighting.
Candidates 5, 7 and 9 eliminated by colouring. Candidate '8' auto highlighted.

SudokEx will not solve a puzzle automatically. Its main job is to maintain the 'candidates list'. This task is tedious and error-prone when attempted manually. With SudokEx you are then free to concentrate on the more interesting challenge of spotting patterns that may be exploited by the traditional Sudoku solving techniques. SudokEx will, however, highlight 'single square candidates' for you. Some puzzles can be solved using this feature alone. In addition, you can save a puzzle at any stage in your work to allow a speculative solution (AKA a guess) to be tried while retaining the ability to return to the earlier state of play.

The script

Your cell-meister is not the first to suppose that Excel and Sudoku were made for each other. They're both about numbers in boxes, yes? Well, having written nothing in VBA script before, I would think that, wouldn't I? Although it isn't the worst language in the world by a long stretch, it sometimes seems to have the simplicity of C++ combined with the elegance of Perl. The performance is also a hoot: two minutes to set up the sheet.

There are indeed some far more impressive implementaions available than SudokEx. Most of those, however, need VBA macros enabled to function at all. That presented here can be understood and extended relatively easily (just not by me; I'm moving on).

Tips for using SudokEx.

SudokEx isn't really going to solve puzzles for you; it just handles the 'donkey work' of candidate lists and checking for single square candidates. You aren't even prevented from entering incorrect solutions. If you do so then, somewhere along the line, you will see the candidate list for one of the squares shrink to nothing, or there will be two single square candidates in the same box, and you will have to rethink.

If you need to exclude a candidate then just type '0' over it. To repair the change, copy the formula for that specific cell from a fresh copy of SudokEx. With SudokEx.xlsm you can run the script at any time to return to the puzzle start state on Sheet1. Solution digits may be retracted in the same way.

Not every single candidate square is also a single square candidate, so you should keep an eye open for them yourself. Fortunately they are fairly obvious.

In version 2 I have added a facility to show or hide all candidates for a specific number or numbers across the whole puzzle. This is of great utility when looking for X-wing instances, row claims, box claims, groups and forcing sequences etc. The controls for this are in the first nine cells of column A. To hide all candidate '7's, for example, change A7 from 'S' to 'h' or 'H'. To make the '7's visible again, change A7 back to 'S' (or anything except 'h'). If you wish to change several candidates at once then either 'fill down' or simple copy/paste will work.

Colouring candidates.
Candidates 5, 7 and 9 eliminated by colouring. Three eliminated candidates, and one solution.

SudokEx is really great for 'colouring'. Often a puzzzle will become intractable with at least one square having only two candidates. Which should you choose? Well, you could get SudokEx to bifurcate the puzzle on a randomly chosen candidate, but this isn't playing the game according to some authorities. You might also change the background colour on your chosen candidate to highlight the way you intend to jump. Don't do that. Instead change the foreground (font) colour from the default black to, say, light red. Having done that, you can immediately see which other candidates in the same house are eliminated. Select all of those and change their font to light blue. The chances are good doing that will reveal another candidate that must be a solution and can also be turned red. You keep going in this way until either 1) all candidates are red or blue, and the puzzle is solved, or 2) the candidates enter a state inconsistent with a valid puzzle, and you made the wrong choice for your first step. If you encounter the latter condition, then it is very easily reversed without having to hit 'undo' fifty times. Just make a rectangular selection that includes all the red and blue candidates and change the font back to black.