Sudoku COPILOT

We’re always on the lookout for ways to automate repetitive tasks in Excel. And today, we’re diving into something a bit more fun: building Sudoku puzzles in Excel with the COPILOT and WEBSERVICE functions. Whether you’re a puzzle enthusiast or just looking to expand your Excel skills using its latest AI tools, this practical walkthrough has something for everyone.

Video

Step-by-Step Guide: Creating a Sudoku Puzzle in Excel

We’ll retrieve a Sudoku puzzle from a free live web service with the WEBSERVICE function, use the new COPILOT function to format it beautifully into a grid, and then apply some standard cell formatting to make it look awesome.

Step 1: Retrieve the Puzzle with WEBSERVICE

To start, we use the WEBSERVICE function to get data from a URL that provides both a Sudoku puzzle and its solution. This function can pull in content from a web API directly into Excel.

The URL used in this example (which you can paste into a normal web browser):

https://www.youdosudoku.com/api

It returns a set of 81 digits that represent the Sudoku puzzle, and another string with the solution, that looks like this:

{"difficulty":"easy","puzzle":"001200460040056008697100203160400590405002600002500300000300849000680720084005030","solution":"851239467243756918697148253168473592435892671972561384526317849319684725784925136"}

We can actually pull this directly into a cell with the WEBSERVICE function.

The WEBSERVICE function retrieves data from a web service (HTTP or HTTPS) and returns the response as text into the Excel cell.

=WEBSERVICE(url)
  • url -a text string containing the URL of the web service.
    • Must begin with http:// or https://
    • Can be a direct URL or a cell reference that evaluates to a valid URL
    • Returns #VALUE! if the URL is invalid or inaccessible

So, assuming we store the URL in B6, we can use the following formula in another cell such as B8 to retrieve a random puzzle/solution:

=WEBSERVICE(B6)

The result comes back as a string of 81 digits, which is the row-wise data of the Sudoku puzzle, and another 81 for the solution.

Note: each digit corresponds to a cell in the 9×9 Sudoku grid.

Step 2: Format the Puzzle Using the COPILOT function

With the raw data retrieved, the next challenge is turning that long string into a nicely formatted Sudoku grid inside the Excel spreadsheet. While this might normally require complex formulas or Power Query, the COPILOT function simplifies the process dramatically.

The COPILOT function sends a prompt to Excel’s integrated Copilot service and returns the generated text response directly into a cell or range of cells. It allows you to use natural language to generate or transform content inside the workbook. You pass a prompt and context (cell range) in pairs. We could use the following formula to break the 81 digit string into a sudoku grid:

=COPILOT("Create the sudoku puzzle grid", B8)

Here, B8 refers to the cell returned by the WEBSERVICE function. Copilot interprets the prompt and restructures the data into a grid format:

Note: You’ll need access to the COPILOT function (currently being rolled out). If it isn’t available in your version, check out our Power Query version of this tutorial.

Step 3: Suppress 0 values

The API returns a 0 to represent a cell that needs to be solved … that is, a blank puzzle cell. So, we now need to replace any 0 with an empty string so it appears blank. There are, as with anything in excel, many options. Here, we’ll use the SUBSTITUTE function.

The SUBSTITUTE function replaces occurrences of specific text within a string with new text. It’s useful when you need to replace one or more instances of a substring without using case-sensitive formulas.

=SUBSTITUTE(text, old_text, new_text, [instance_num])
  • text(required)
    • The original text string (or a cell reference containing text) where substitutions will occur.
  • old_text(required)
    • The text you want to replace.
    • Case-sensitive.
  • new_text(required)
    • The replacement text.
    • Can be an empty string ("") if you want to remove the old_text.
  • instance_num(optional)
    • Specifies which occurrence of old_text to replace.
    • If omitted, all occurrences of old_text are replaced.
    • If provided, only that numbered occurrence is replaced (1 = first, 2 = second, etc.).

So, we can update our formula as follows:

=SUBSTITUTE(COPILOT("create the sudoku puzzle grid",B8),"0","")

The updated puzzle:

Step 4: Beautify Your Grid

To make the puzzle grid visually appealing:

  • Apply borders: Select the grid and apply all borders.
  • Increase row height: Set it to ~40 for better spacing.
  • Center values: Use horizontal and vertical alignment options.
  • Optional: Use thicker outside borders for 3×3 sections to mimic a Sudoku layout more accurately.

Step 5: Retrieve and Format the Solution

Now that we’ve formatted the puzzle, we can apply the same steps to render its solution.

=COPILOT("Create the sudoku solution grid", B8)

Instead of formatting the solution manually, you can copy the puzzle cells and paste it’s formatting to the solution cells using Paste > Paste Special > Formats.

Step 7: Get a New Puzzle

Want to refresh and get a brand new puzzle? Simply press:

Ctrl + Alt + F9

This forces Excel to recalculate all functions, including WEBSERVICE, which typically caches results. After pressing the shortcut, the fetched data refreshes, and your COPILOT formulas automatically update the puzzle and solution accordingly.

Summary

Using the WEBSERVICE and COPILOT functions together allows us to automate the import, layout, and display of Sudoku puzzles directly in the grid. And with custom formatting tricks, we can refine the visual display entirely within Excel.

While it’s a fun demo, this exercise also underscores the potential of the COPILOT and WEBSERVICE functions not just for puzzles, but for real-world data transformation and formatting tasks.

Download the Sample File

Frequently Asked Questions (FAQs)

What is the WEBSERVICE function in Excel?
It retrieves data from a specified URL and displays the result inside a cell. It’s ideal for accessing live data feeds like our Sudoku puzzle source.
Why doesn’t my Excel recognize the COPILOT function?
COPILOT is still being rolled out and may not be available in all environments. If your Excel version doesn’t support COPILOT, consider using the Power Query approach as an alternative.
Can I use COPILOT for other grid-based puzzles?
Absolutely. Copilot can interpret prompts and restructure data into grids depending on your input and context.
What Excel versions support COPILOT
Excel Copilot is currently in Microsoft 365 for Business and Enterprise customers. It will gradually roll out to eligible users later in the year.
Can COPILOT replace VBA for puzzles?
In some use cases, yes. For puzzles and basic text/data transformations, COPILOT offers a simpler, no-code alternative.
How do I refresh the WEBSERVICE function in Excel?
Use Ctrl + Alt + F9 to force a complete recalculation, which includes re-fetching URL content.
Will custom formatting persist with new puzzles?
Yes — as long as the data structure remains the same, the formatting applied to the grid will persist after refreshing the puzzle data.

 

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