Excel Formula for Filtering Address Databases by Zip Code Radius

📅 Apr 26, 2026 📝 Sarah Miller

Managing expansive address databases and filtering them by precise zip code radii in Excel is notoriously tedious and prone to manual error. While organizations often look to standard funding sources to acquire enterprise-grade GIS software, a native spreadsheet solution remains highly accessible. This mathematical approach grants users immediate, cost-free spatial filtering capabilities directly within their existing workflows.

A key stipulation, however, is that Excel requires pre-calculated latitude and longitude coordinates to compute great-circle distances accurately. Used successfully by regional delivery services to optimize local routing, this method bridges the gap between raw data and spatial insight. Below, we outline the exact formulas and setup steps to construct your radius filter.

Excel Formula for Filtering Address Databases by Zip Code Radius

In sales, marketing, and logistics, location intelligence is everything. Whether you are planning a localized direct mail campaign, assigning sales territories, or finding the closest distribution hubs to your customers, filtering an address database based on geographic proximity is a critical task. While dedicated Geographic Information System (GIS) software can do this, you do not need expensive tools to accomplish it. With a few creative formulas and a reference database, you can build a dynamic, radius-based zip code filter directly in Microsoft Excel.

This guide will walk you through setting up an interactive Excel model that calculates the distance between a target zip code and your entire address database, allowing you to instantly filter for records within a specified mile or kilometer radius.

The Methodology: How Excel Calculates Distance

Since Excel does not naturally understand geographic coordinates, we must provide it with two things: the latitude and longitude of our zip codes, and a mathematical formula to calculate the distance between those coordinates on a sphere.

To calculate the distance between two points on the Earth's surface, we use the Spherical Law of Cosines. While the Haversine formula is also popular, the Law of Cosines is slightly shorter and highly accurate for calculating terrestrial distances in standard spreadsheet applications. The mathematical formula is represented as:

d = acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon2 - lon1) ) * R

Where:

  • lat1, lon1: Coordinates of the starting point (radians)
  • lat2, lon2: Coordinates of the destination point (radians)
  • R: The radius of the Earth (3,959 miles or 6,371 kilometers)

Step 1: Prepare Your Data Tables

To implement this in Excel, you will need two tables within your workbook:

1. The Customer/Address Database

This is your primary list. It should contain columns like Customer Name, Address, City, State, and most importantly, the Zip Code. Let's assume this table is named tblCustomers.

2. The Zip Code Coordinates Reference Table

You need a clean database containing every zip code in your target country along with its corresponding Latitude and Longitude. Free databases for US Zip Codes are widely available online in CSV format. Import this into a sheet named ZipReference and convert it into an Excel Table named tblZipRef with three core columns: Zip, Latitude, and Longitude.

Step 2: Create the User Control Panel

Set up a small control panel in an empty sheet or at the top of your workspace. This is where you will input your target parameters:

  • Cell H2: Target Zip Code (e.g., 90210)
  • Cell H3: Maximum Radius in Miles (e.g., 25)

Step 3: Retrieve Coordinates Using XLOOKUP

Before we can calculate distances, we need Excel to look up the latitude and longitude of the target zip code (from cell H2) and each customer's zip code in our database. We will use the modern XLOOKUP function for this.

To find the Latitude of our target zip code (H2), we use:

=XLOOKUP(H2, tblZipRef[Zip], tblZipRef[Latitude], "Not Found")

To find the Longitude of our target zip code, we use:

=XLOOKUP(H2, tblZipRef[Zip], tblZipRef[Longitude], "Not Found")

Step 4: The Unified Distance Formula in Excel

Now, we will add a new column to our customer database (tblCustomers) called Distance (Miles). Excel's trigonometric functions (SIN, COS, ACOS) work in radians, not degrees. Therefore, we must wrap every latitude and longitude degree value in the RADIANS() function.

Assuming the customer's Zip Code is in cell E5, the target zip code is in $H$2, and your lookup formulas are nested, the complete Excel formula for the distance column looks like this:

=LET(
    target_lat, XLOOKUP($H$2, tblZipRef[Zip], tblZipRef[Latitude]),
    target_lon, XLOOKUP($H$2, tblZipRef[Zip], tblZipRef[Longitude]),
    cust_lat, XLOOKUP(E5, tblZipRef[Zip], tblZipRef[Latitude]),
    cust_lon, XLOOKUP(E5, tblZipRef[Zip], tblZipRef[Longitude]),
    earth_radius, 3959,
    
    IF(OR(ISNA(cust_lat), ISNA(target_lat)), "Unknown Zip",
        ACOS(
            SIN(RADIANS(target_lat)) * SIN(RADIANS(cust_lat)) + 
            COS(RADIANS(target_lat)) * COS(RADIANS(cust_lat)) * 
            COS(RADIANS(cust_lon) - RADIANS(target_lon))
        ) * earth_radius
    )
)

Formula Breakdown:

  • LET Function: Used to define variables (like target_lat and cust_lat). This prevents Excel from performing the same duplicate XLOOKUP queries multiple times, drastically increasing calculation speeds on large databases.
  • earth_radius (3,959): We use 3,959 for miles. If you want kilometers, change this value to 6371.
  • IF/OR Statement: Handles errors gracefully. If a zip code in your list is missing from your reference guide, it returns "Unknown Zip" instead of an ugly #N/A or #VALUE! error.

Step 5: Filtering the Address Database

Now that your database calculates the distance to the target zip code dynamically for every row, you can filter this data using two different methods depending on your version of Excel.

Method A: Classic AutoFilter (All Excel Versions)

  1. Click anywhere inside your customer table.
  2. Go to the Data tab on the Ribbon and click Filter.
  3. Click the filter dropdown arrow on your new Distance (Miles) column.
  4. Select Number Filters > Less Than Or Equal To....
  5. Click the cell picker or type in your threshold (or link it to your radius control cell, $H$3).
  6. Click OK. Your database will hide all customers outside your specified radius.

Method B: Dynamic Arrays (Excel 365 & 2021)

If you are using modern Excel, you can keep your master database clean and generate an auto-updating, filtered list on a separate sheet using the FILTER function.

On your dashboard/reporting sheet, write the following formula:

=FILTER(tblCustomers, (tblCustomers[Distance (Miles)] <= H3) * ISNUMBER(tblCustomers[Distance (Miles)]), "No Locations Found")

This dynamic formula checks the Distance column in your customer table, compares it to your maximum radius input in cell H3, and instantly spills a list of all matching rows. If you change the Target Zip Code in H2 or the radius in H3, the entire filtered table will instantly recalculate and redraw itself.

Performance Tips for Large Databases

If you are working with address databases containing 50,000+ rows, heavy trigonometric formulas combined with nested lookups can cause Excel to lag. Use these optimization tips to keep your workbook lightning-fast:

  • Pre-calculate Customer Coordinates: Do not run XLOOKUP inside the distance formula for every customer row. Instead, create static Latitude and Longitude columns directly in your customer database and pull the coordinates once. Then, refer to those static cells in your distance formula.
  • Switch to Manual Calculation: If you are actively importing or editing data, go to the Formulas tab > Calculation Options > Manual. Switch it back to Automatic only when you are ready to query your radius.

Conclusion

By leveraging basic trigonometry and modern lookup functions, you can turn Microsoft Excel into a powerful geographic analysis engine. This radius-filtering tool allows you to target marketing efforts, streamline logistics paths, and make data-driven territorial decisions without ever leaving your spreadsheet.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.