Excel Formula Completion: How to Extract Zip Codes from Text with REGEXEXTRACT

Excel Formula Completion: How to Extract Zip Codes from Text with REGEXEXTRACT

Excel's Formula Completion feature can write formulas for you. Just press the equal sign, and Excel suggests the formula based on your data and column headers. In this tutorial, I demonstrate how it works by tackling a common challenge: extracting zip codes from messy address data where the zip code appears in different positions within each cell.

The Challenge: Zip Codes in Different Positions

The dataset contains customer addresses in column C, with zip codes embedded at various positions — some at the beginning, some in the middle, some at the end. The goal is to extract just the five-digit zip code into column D.

Excel spreadsheet showing customer addresses with zip codes in varying positions and an empty Zip Code column
The starting data: addresses with zip codes scattered in different positions. Column D is ready for the extracted values.

Step 1: Add a Column Header

Before triggering Formula Completion, add a descriptive column header. I typed "Zip Code" in cell D1. This is important because Excel uses column headers to understand what you want to extract — the header guides the AI suggestion.

Step 2: Trigger Formula Completion

Click on cell D2 (the first data row) and press the equal sign (=). Excel's Formula Completion immediately suggests a REGEXEXTRACT formula:

Excel Formula Completion suggesting REGEXEXTRACT formula with tooltip showing Extract zip code from address
Formula Completion suggests =REGEXEXTRACT(C2,"\b\d{5}\b",0,0) with a tooltip confirming it will extract the zip code from the address.

The suggested formula is =REGEXEXTRACT(C2,"\b\d{5}\b",0,0). Here is what the regex pattern means:

  • \b — word boundary (ensures we match a standalone number, not part of a longer number)
  • \d{5} — exactly five digits
  • \b — closing word boundary

Press Tab to accept the suggestion.

Step 3: Fill Down and Verify

After accepting the formula for the first row, fill it down to all remaining rows. The formula correctly extracts the five-digit zip code from every address, regardless of where it appears in the cell.

Excel spreadsheet showing all zip codes successfully extracted into column D using REGEXEXTRACT
All zip codes extracted correctly — the REGEXEXTRACT formula handles addresses with zip codes in any position.

Requirements

Formula Completion requires a Microsoft 365 Copilot license, Excel for the web, and Beta channel access. It is not yet available in the desktop version of Excel.

How to Extract Numbers from Text in Excel with REGEXEXTRACT
Excel's REGEXEXTRACT function lets you pull numbers (or any pattern) out of a text string using regular expressions. Unlike functions like TEXTAFTER or TEXTBEFORE that depend on consistent delimiters, REGEXEXTRACT works with messy, inconsistent data — it finds the pattern wherever it appears. In this walkthrough, you'll see two practical examples: extracting 10-digit phone numbers from a name-and-number string, and pulling numbers from completely unstructured text. You'll also learn how to hand
Excel FORMULA Completion vs COPILOT(): When to Use Each Feature
I use both Formula Completion and the Copilot function in Excel every week. They require a paid Microsoft 365 Copilot license. They solve different problems, and when you combine them, you can move from repetitive calculations to higher-level text analysis and data cleanup in minutes. Below, I explain what each tool is best suited to, provide practical examples, and share a few tips to save time and reduce errors. At a glance: which tool for which job * Formula Completion is perfect for nume
Excel Formula Completion - Using XLOOKUP
I tested how well Excel's formula completion with Copilot handles a multi-step calculation that would normally require a nested function. The goal was simple: calculate profit by subtracting the total cost of units sold from total revenue, with unit costs stored in a separate lookup table. Instead of writing the full formula by hand, I typed a single equals sign and let Copilot generate the formula for me. The result was impressive. Note: Microsoft 365 Copilot License is required (Paid version
Extract email addresses from a text string in Excel
Extracting email address from a text string in Excel can be tricky. I made a video demonstrating three methods of extracting the email addresses. I also showed how to take the email addresses and add a comma between them. This is handy when you need to import the email addresses into an LMS or another system. Three ways to separate the data 1. Mid and Find Function in Excel. 2. Flash Fill in Excel 2013 and Excel 2016 for Windows. 3. Text to Columns for any Excel version. One of my favorite f

Want to learn more? Visit courses.chrismenardtraining.com for online training courses.

Read more