Generate Sudoku in Excel with Free API

Did you know we can auto-generate Sudoku puzzles right inside Excel, without manually entering grid layouts? With the WEBSERVICE function and a little help from a Sudoku API, we can create both a playable Sudoku puzzle and its corresponding solution dynamically. In this step-by-step guide, we’ll show how to make a Sudoku board using Excel’s built-in functions like WEBSERVICE, LET, and SEQUENCE.

Video

This is a great example of how Excel goes beyond number crunching to support fun, logic-based applications using APIs. Let’s dive in.

Exercise 1: Calling the Sudoku API

We start by retrieving puzzle data from the Sudoku API.

For this we’ll use the WEBSERVICE function.

WEBSERVICE retrieves data from a specified web address (URL) and returns it as a text string.

Signature:

WEBSERVICE(url)

Arguments:

  • url — The web address of the resource you want to retrieve, enclosed in quotation marks or referenced from a cell.

So, in any cell, we use Excel’s WEBSERVICE function along with the desired API URL:

=WEBSERVICE("https://www.youdosudoku.com/api/")

Note: an alternative sudoku api is here: https://sudoku-api.vercel.app/api/dosuku

This function sends a request to the API and returns a JSON string containing:

  • The difficulty level
  • The puzzle string (81 characters, left-to-right, top-to-bottom)
  • The corresponding solution string

In our sample file, this call returns something like:

{"difficulty":"easy","puzzle":"006001090…","solution":"..."

At this point, we have the raw puzzle, but it’s still in one long string. Let’s break it out into a usable grid.

Exercise 2: Parsing the Puzzle String

In this step, we’ll pull just the puzzle digits from the string and lay them out into a 9×9 range.

Let’s assume the WEBSERVICE function and thus raw puzzle string is in D6 and looks a bit like this:

Here is one set of formulas that will extract the puzzle and lay it out in a classes sudoku grid.

Step 1 – Find where the puzzle starts

First, we will locate the word "puzzle" in the API response in D6. For this we will use the FIND function.

FIND returns the position of a specific substring within another text string, counting from the first character.

Signature:

FIND(find_text, within_text, [start_num])

Arguments:

  • find_text — The text you want to locate.
  • within_text — The text string in which to search.
  • start_num (optional) — The character position in within_text where the search should begin; defaults to 1.

So, we can write the following formula in D7:

=FIND("puzzle",D6)

It returns a number, such as 23, which tells us the character position of the word "puzzle" within the returned api string:

Step 2 – Extract the puzzle string

We know puzzle":" is followed immediately by the 81 puzzle digits. Since we want to start our extraction at the puzzle itself (and exclude the word puzzle), we add 9 to skip past puzzle":" and get the puzzle digits. For this task, we’ll use the MID function.

MID returns a specific number of characters from a text string, starting at a given position.

Signature:

MID(text, start_num, num_chars)

Arguments:

  • text — The text string containing the characters you want to extract.
  • start_num — The position of the first character you want to extract.
  • num_chars — The number of characters to return from start_num.

We use the following formula in D8:

=MID(D6,D7+9,81)

This gives us a single 81-character string like this:

Step 3 – Lay out the 9×9 grid

Next, we need to layout the puzzle in the 9×9 grid. For this, we’ll use the SEQUENCE function to create the position numbers for the MID function.

SEQUENCE generates an array of sequential numbers in rows and columns, starting from a specified number and incrementing by a specified amount.

Signature:

SEQUENCE(rows, [columns], [start], [step])

Arguments:

  • rows — The number of rows to fill.
  • columns (optional) — The number of columns to fill; defaults to 1.
  • start (optional) — The first number in the sequence; defaults to 1.
  • step (optional) — The amount to increment each subsequent number; defaults to 1.

We use SEQUENCE to generate positions from 1 to 81, and leverage the MID function to grab the puzzle digit at each position:

=MID(D8,SEQUENCE(9,9),1)

This instantly fills a 9×9 block with the puzzle’s numbers:

Step 4 – Remove the zeros

In our Sudoku puzzle, we need to replace any 0s with a blank. For this, we’ll use the SUBSTITUTE function.

SUBSTITUTE replaces all occurrences of a specified substring within a text string with another substring.

Signature:

SUBSTITUTE(text, old_text, new_text, [instance_num])

Arguments:

  • text — The original text string.
  • old_text — The substring you want to replace.
  • new_text — The substring to replace old_text with.
  • instance_num (optional) — Specifies which occurrence of old_text to replace; if omitted, all occurrences are replaced.

So, we use SUBSTITUTE to replace zeros with an empty string:

=SUBSTITUTE(MID(D8,SEQUENCE(9,9),1),0,"")

We are looking much better!

Now we just need to apply some cosmetic formatting.

Exercise 3: Formatting & combining into one formula

At this point, we need to apply some nice formatting, combine the formulas into a single formula, and talk about refreshing the puzzle.

First, we retrieve the puzzle and solution from the api into B5:

Now, let’s display the puzzle and solution.

Combining

Rather than extracting and displaying the puzzle with a series of formulas, let’s combine them into one. For this task, we’ll stay organized by using the LET function. The LET function allows us to create name/value pairs that operate within the scope of the formula.

LET assigns names to calculation results, making formulas easier to read and potentially faster to calculate by reusing those named values.

Signature:

LET(name1, value1, [name2, value2, …], calculation)

Arguments:

  • name1 — The first name to assign.
  • value1 — The value or calculation assigned to name1.
  • name2, value2, … (optional) — Additional name/value pairs.
  • calculation — The final formula or expression that uses the assigned names.

In B7, we use the LET function as follows:

=LET(
api,B5,
start,FIND("puzzle",api)+9,
string,MID(api,start,81),
layout,MID(string,SEQUENCE(9,9),1),
clean,SUBSTITUTE(layout,0,""),
clean
)

In summary, this formula pulls the Sudoku puzzle from the API’s JSON response in B5, lays it out in a 9×9 grid, and replaces zeros with blanks.

Let’s break it down step-by-step:

  1. api,B5
    • Stores the full JSON text from cell B5 (the WEBSERVICE result) in the variable api.
  2. start,FIND("puzzle",api)+9
    • Finds where the word "puzzle" occurs in the JSON string.
    • Adds 9 to skip past "puzzle": so we land on the first puzzle digit.
  3. string,MID(api,start,81)
    • Extracts the 81 characters (9×9 grid) starting from that first digit position.
  4. layout,MID(string,SEQUENCE(9,9),1)
    • Uses SEQUENCE(9,9) to generate positions 1 through 81.
    • Pulls each character individually from string, resulting in a 9×9 array.
  5. clean,SUBSTITUTE(layout,0,"")
    • Replaces any 0 (empty Sudoku cells) with an empty string.
  6. clean
    • Returns the final cleaned 9×9 puzzle grid.

In short: This LET formula turns the raw puzzle text from the API into a neatly arranged Sudoku board in Excel.

We can use the same basic technique for the solution grid. All we need to do is replace "puzzle" with "solution" in the FIND step and adjust our start character count. Since solution":" is two characters longer, we adjust the 9 to 11, like this:

=LET(
api,B5,
start,FIND("solution",api)+11,
string,MID(api,start,81),
layout,MID(string,SEQUENCE(9,9),1),
clean,SUBSTITUTE(layout,0,""),
clean
)

These return the correct values to the correct cells. Now we need to make it look like a real sudoku puzzle through formatting.

Formatting

Once both grids are ready, we format them to look like a Sudoku board:

  • Apply All Borders to each grid
  • Apply a Thick Outside Border to each 3×3 grid
  • Center text horizontally and vertically.
  • Increase Row Height to 40 and font size for readability.

The puzzle now looks like this:

And the solution looks like this:

Now, anytime you want a new puzzle, you just refresh. But, a standard F9 won’t work, so let’s talk about that next.

Refreshing the Puzzle

The WEBSERVICE function doesn’t refresh with regular F9. Instead, press:

Ctrl + Alt + F9

This forces Excel to recalculate the WEBSERVICE call and return a new puzzle with its solution.

Conclusion

And there we have it! A fully functioning Sudoku generator in Excel! By combining WEBSERVICE, FIND, MID, SEQUENCE, SUBSTITUTE, and LET, we’ve transformed a stream of raw API text into a clean, interactive puzzle board… without writing a single line of code.

The beauty of this setup is that it’s completely customizable. You could tweak the formatting to match your favorite Sudoku app or even adapt the same approach for entirely different types of api data. The real win here is learning how to take an external data source, break it down step-by-step, and turn it into something fun and functional.

If you give this a try, I’d love to hear how it goes! Did you modify the formulas? Did you come up with a creative twist on the puzzle display? Drop a comment below and share your ideas. Your spin on it might just inspire the next person to push Excel in a whole new direction.

Download the Sample File

Want to try it out? Download the finished workbook below and start solving puzzles directly within Excel.

Frequently Asked Questions

1. What Excel version supports these features?
You’ll need Excel 365 or Excel 2019+, as both LET and SEQUENCE are required.
2. Can I use Power Query instead?
Absolutely—Power Query is another great way to consume web APIs in Excel, but this post focuses on doing it all with worksheet functions. I’ll create a full tutorial on this shortly 🙂
3. How do I prevent the puzzle from updating automatically?
Since we’re using WEBSERVICE, the function doesn’t auto-refresh. To get a new puzzle, press Ctrl + Alt + F9.
4. Why use LET instead of multiple helper cells?
LET makes the formulas more readable and efficient by reducing repetitive calculations and clarifying logic flow.
5. What does the Sudoku API return?
The API returns a JSON-like string that includes the puzzle, solution, and difficulty level.
6. Can I select different difficulty levels?
Depending on the API service you use, you might be able to pass additional parameters in the URL to set difficulty.
7. How accurate is the puzzle solving?
The solution comes directly from the API, ensuring accuracy.
8. Can we use VBA instead?
Yes! VBA offers even more flexibility if you want to build an interactive or automated Sudoku interface.
9. Will this work offline?
No, since it relies on an external web service, an internet connection is required to generate puzzles.

Posted in ,

Jeff Lenning

I love sharing the things I've learned about Excel, and I built Excel University to help me do that. My motto is: Learn Excel. Work Faster.

Excel is not what it used to be.

You need the Excel Proficiency Roadmap now. Includes 6 steps for a successful journey, 3 things to avoid, and weekly Excel tips.

Want to learn Excel?

Our training programs start at $29 and will help you learn Excel quickly.

Leave a Comment