Skip to main content

How to extract postcode from address list in Excel?

Author: Sun Last Modified: 2025-07-11

When managing customer information in Excel, it’s common to have a list of full addresses where each entry contains both street details and a postcode (zip code). If you need to isolate and extract just the postcodes from these addresses—perhaps for mailing lists, regional analysis, or data formatting—manually separating them one by one can be tedious and error-prone, especially with large datasets. Fortunately, Excel offers practical ways to quickly and efficiently extract multiple postcodes at once without manual effort. This article provides step-by-step instructions for extracting postcodes from addresses using an Excel formula and a VBA macro solution.

Extract postcode with formula in Excel

Extract postcode with User Defined Function in Excel


Extract postcode with formula in Excel

In many common address lists, the postcode is located at the end of the address string and is not longer than 8 characters. This method is most suitable when all addresses in your list follow a consistent format and the postcode appears as the last element of each address, separated by spaces.

To quickly extract the postcode using a formula, follow these steps:

1. Select a blank cell where you want the postcode to appear (for example, B1 if your address is in A1). Enter the following formula:

=MID(A1,FIND("zzz",SUBSTITUTE(A1," ","zzz",SUMPRODUCT(1*((MID(A1,ROW(INDIRECT("1:"&LEN(A1))),1))=" "))-1))+1,LEN(A1))

2. Press the Enter key. The postcode from the address in A1 will be displayed in the selected cell.

3. To apply this formula to other addresses, select the cell with the formula, drag the fill handle down along the column to cover all address rows, and Excel will automatically extract the postcode for each address.

a screenshot of extracting postcode from address list with formula

Tip: This formula assumes that the postcode is the last item after the final space in the address string. If your addresses are structured differently, such as postcodes appearing in the middle, or separated by commas, this formula may not return the correct result. To extend this method for international postal codes or custom formats, you may need a different or more advanced formula approach, or try the VBA solution below.


Extract postcode with User Defined Function in Excel

If your address data is more complex, inconsistent, or contains postcodes in various formats and positions within the string as following screenshot shown, a VBA macro can provide more flexible extraction options. This automated method quickly processes an entire column of addresses to isolate and return only the postcodes, saving significant time and minimizing manual effort.

 extract various postcodes from address list

1. Press Alt + F11 to open the Microsoft Visual Basic for Applications window.

2. In the VBA window, click Insert > Module to create a new module. Copy and paste the following VBA code into the module window:

Public Function ExtractPostcode(text As String) As String
    Dim reg As New RegExp
    Dim m As MatchCollection
    reg.Pattern = "\b([A-Z]{1,2}\d{1,2}[A-Z]?\s*\d[A-Z]{2}|\d{5}(?:-\d{4})?|\d{6})\b"
    reg.IgnoreCase = True
    reg.Global = False
    
    If reg.Test(text) Then
        Set m = reg.Execute(text)
        ExtractPostcode = m(0).Value
    Else
        ExtractPostcode = ""
    End If
End Function

3. After pasting the code, In the vba editor windown, choose Tools > References. See screenshot:

click Tools > References

4. In the References dialog box, check Microsoft VBScript Regular Expressions 5.5 and click OK.

check Microsoft VBScript Regular Expressions 5.5

5. Return to the worksheet, and enter this formula: =ExtractPostcode(A2), drag the fill-handle down to other cells. All postcodes are displayed at once, see screenshot:

tye a formula to get the result

Tip: With this code, you can automatically extract postal codes from any country or region in Excel in just seconds; by simply tweaking the regular expression to match the postal-code rules of your target area, you can quickly adapt to different formats—such as the UK’s “SW1A 1AA,” the US’s “12345-6789,” or China’s “100000”—greatly boosting your data-cleaning and analysis efficiency.


Relative Articles:


Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more
Use Kutools in your preferred language – supports English, Spanish, German, French, Chinese, and 40+ others!

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!