TutorialsBy the Shapedoku TeamPublished 7 min read

How to Solve Sudoku in a Spreadsheet

You can solve Sudoku in a spreadsheet without a line of real code, using nothing but a tidy grid, a handful of helper formulas, and the built-in optimizer most spreadsheet apps already ship with.

Set up the grid

Start by choosing a 9 by 9 range, for example B2 to J10, and giving each of the nine 3 by 3 boxes a thick border so the structure is visible. Type the givens as fixed numbers and leave the rest blank. Add data validation to the whole range so cells only accept whole numbers from 1 to 9; that alone catches many typing mistakes before they ever cause a wrong answer. This clean layout is the foundation for everything else, because every formula you add will reference these coordinates. To solve Sudoku in a spreadsheet you first need a spreadsheet that models the board honestly.

Detect conflicts with COUNTIF

The heart of Sudoku is a simple rule: no digit repeats in a row, a column, or a box. COUNTIF turns that rule into a formula. For any cell, count how many times its value appears in its row; if the result is greater than one, you have a duplicate. Do the same for the column and the box. Wire these three checks into conditional formatting so any offending cell turns red the instant a conflict appears. Now the spreadsheet is a live rule-checker, quietly validating every move you make.

Track candidates per cell

To solve by logic you need pencil marks, and a spreadsheet can compute them for you. Off to the side, build a helper block that, for each empty cell and each digit, tests whether that digit is absent from the cell's row, column, and box. If a digit passes all three tests, it is a candidate. A cell whose candidate list has shrunk to a single value is a naked single, and you can safely fill it in. Watching those candidate lists collapse as you type is genuinely satisfying.

Solve by logic first

Because a spreadsheet recalculates continuously, every number you enter immediately trims the candidate lists of related cells. Work the easy deductions by hand: fill the naked singles, then look for hidden singles, where a digit can go in only one place within a unit. Many gentle puzzles fall completely to this back-and-forth, and you never had to write a program at all. The spreadsheet is doing the bookkeeping while you supply the reasoning.

Automate the search with the Solver add-in

Harder puzzles resist pure logic and need a search. Both Excel and Google Sheets offer an optimizer add-in that can model Sudoku as an integer program. The classic setup uses binary variables, one for each combination of cell, row, and digit, meaning this cell holds this digit or it does not. You then add constraints: every cell takes exactly one digit, and every digit appears exactly once in each row, column, and box. The optimizer searches for an assignment that satisfies all of them. It is heavier than logic but it can finish puzzles a formula-only approach cannot.

Limits of the spreadsheet approach

  • Plain formulas cannot backtrack, so they stall on puzzles that require guessing.
  • Naive candidate loops can create circular references if you are not careful.
  • The Solver add-in can time out or need tuning on the very hardest grids.
  • It is a great way to learn constraints, but it will never rival a real solver on speed.

Why this is a great learning exercise

Modeling Sudoku this way forces you to state the rules with total precision, which is exactly the skill that transfers to writing a real solver later. You see, in ordinary formulas, why constraint propagation is powerful and why search is sometimes unavoidable. Once you can solve Sudoku in a spreadsheet, the leap to a small program in Python or JavaScript feels natural. And when you want a break from formulas, the shape puzzles at shapedoku.com give your logic muscles the same workout with a calmer, more colorful interface.

Ready to put it into practice?

Play Shapedoku free in your browser. No download, no login, just colorful shape Sudoku.

Play the Web App

Keep reading