Calculate Miles Between Zip Codes in Excel

Montreal Jul 09, 2026

Calculating the distance between two zip codes can be a useful task, especially for businesses with multiple locations or delivery services. While there are numerous tools and APIs available online, you can also perform this calculation directly in Microsoft Excel using a simple formula. This article will guide you through the process of calculating miles between zip codes in Excel.

How to Calculate Driving Distance between Two Addresses in Excel
How to Calculate Driving Distance between Two Addresses in Excel

Before we dive into the steps, it's important to note that Excel doesn't have a built-in function to calculate distance between two zip codes. However, we can use the Haversine formula, which calculates the shortest distance between two points on the surface of a sphere. To use this formula, we'll first need to find the latitude and longitude of the zip codes.

Get Mileage from Excel Lookup Table - Contextures Blog
Get Mileage from Excel Lookup Table - Contextures Blog

Finding Latitude and Longitude of Zip Codes

To find the latitude and longitude of a zip code, you can use various online tools and APIs. One such tool is the USPS Zip Code API, which provides latitude and longitude data for US zip codes. Alternatively, you can use Google Maps to find the coordinates of a zip code and then extract the latitude and longitude from the URL.

Split Address With Excel Formulas - Contextures Blog
Split Address With Excel Formulas - Contextures Blog

Once you have the latitude and longitude for both zip codes, you can proceed to calculate the distance between them in Excel.

Using the Haversine Formula in Excel

217K views · 837 reactions | Geography Data Types in Excel‼️ Level up in Excel in one hour!!! 💃🏼 You’re invited to a FREE Excel class w/ Miss Excel! 🎉 Registration + Replay Access = linktr.ee/CheatSheets 📚 Topic: | CheatSheets
217K views · 837 reactions | Geography Data Types in Excel‼️ Level up in Excel in one hour!!! 💃🏼 You’re invited to a FREE Excel class w/ Miss Excel! 🎉 Registration + Replay Access = linktr.ee/CheatSheets 📚 Topic: | CheatSheets

The Haversine formula calculates the distance between two points on a sphere given their latitudes and longitudes. In Excel, you can use this formula to calculate the distance between two zip codes. Here's the formula:

2 * 3963 * ASIN(SQRT(ABS(SIN((lat2-lat1)/2))^2 + COS(lat1) * COS(lat2) * ABS(SIN((lon2-lon1)/2))^2))

Where:

Keep Leading Zeros Fast in Excel
Keep Leading Zeros Fast in Excel
  • lat1 and lon1 are the latitude and longitude of the first zip code.
  • lat2 and lon2 are the latitude and longitude of the second zip code.
  • The distance is calculated in miles, and 3963 is the radius of the Earth in miles.

Applying the Formula in Excel

To use the Haversine formula in Excel, follow these steps:

ms excel formula
ms excel formula
  1. Enter the latitude and longitude of the first zip code in two cells (e.g., A1 and B1).
  2. Enter the latitude and longitude of the second zip code in two cells (e.g., A2 and B2).
  3. In a new cell (e.g., C1), enter the Haversine formula, replacing lat1, lon1, lat2, and lon2 with the cell references containing the zip code coordinates (e.g., =2 * 3963 * ASIN(SQRT(ABS(SIN((B2-A2)/2))^2 + COS(A2) * COS(B2) * ABS(SIN((C2-B2)/2))^2))).
  4. Press Enter to calculate the distance between the two zip codes.

You can then format the cell as a number with decimal places to display the distance to the desired precision.

Highlight Duplicate Data in Excel with Just a Click!
Highlight Duplicate Data in Excel with Just a Click!
How to use frequency formula in excel
How to use frequency formula in excel
How to Add Zero 0 before Number in Microsoft Excel #shorts #ytshorts #studyspan
How to Add Zero 0 before Number in Microsoft Excel #shorts #ytshorts #studyspan
Create Form in Excel for Data Entry | MyExcelOnline
Create Form in Excel for Data Entry | MyExcelOnline
Tips & Tricks - Excel - ZIP Codes Zero
Tips & Tricks - Excel - ZIP Codes Zero
Microsoft Excel Cheat Sheet | Essential Formulas, Shortcuts & Productivity Tips
Microsoft Excel Cheat Sheet | Essential Formulas, Shortcuts & Productivity Tips
101 best key excel formulas & functions examples
101 best key excel formulas & functions examples
an excel spreadsheet with the text shift p and tick mark highlighted in yellow
an excel spreadsheet with the text shift p and tick mark highlighted in yellow
#exceltips #exceltricks #exceltutorial #msexcel #spreadsheet #exceldata Basic Excel, Excel Sheet, Excel Training, Excel To Do List, Excel Tutorials Videos, Excel Tricks, Excel Formulas, Excel Tips, Assignment Sheet
#exceltips #exceltricks #exceltutorial #msexcel #spreadsheet #exceldata Basic Excel, Excel Sheet, Excel Training, Excel To Do List, Excel Tutorials Videos, Excel Tricks, Excel Formulas, Excel Tips, Assignment Sheet
a screen shot of the track mileage page
a screen shot of the track mileage page
How to Combine Multiple Data Sets in Microsoft Excel Using Power Query
How to Combine Multiple Data Sets in Microsoft Excel Using Power Query
How to Sort and Filter Data in Excel - A Complete Guideline - ExcelDemy
How to Sort and Filter Data in Excel - A Complete Guideline - ExcelDemy
how to calculate hours worked
how to calculate hours worked
excel useful formulas
excel useful formulas
Mileage Tracker Excel & Google Sheets Spreadsheet Template
Mileage Tracker Excel & Google Sheets Spreadsheet Template
How to Calculate Over Time in Excel 🔥#excel #shortsvideo #exceltips #tipsntricks #exceltutorial
How to Calculate Over Time in Excel 🔥#excel #shortsvideo #exceltips #tipsntricks #exceltutorial
Copy Data From One Sheet to Another in Excel
Copy Data From One Sheet to Another in Excel
Excel Formulas You Should Know
Excel Formulas You Should Know
the excel shortcuts list is shown with green and black numbers on it, which are
the excel shortcuts list is shown with green and black numbers on it, which are
Top Ways to Add a Zero in Front of a Number in Excel (+ video tutorial)
Top Ways to Add a Zero in Front of a Number in Excel (+ video tutorial)

Calculating Distance Between Multiple Zip Codes

If you need to calculate the distance between multiple zip codes, you can use Excel's built-in functions to automate the process. Here's how:

Assuming your zip code data is in columns A and B (with latitudes in A and longitudes in B), you can use the INDEX and MATCH functions to find the coordinates of the second zip code. Then, use the Haversine formula to calculate the distance. Here's the formula:

=2 * 3963 * ASIN(SQRT(ABS(SIN((INDEX(B:B,MATCH(A2,B:B,0))-B2)/2))^2 + COS(B2) * COS(INDEX(B:B,MATCH(A2,B:B,0))) * ABS(SIN((INDEX(C:C,MATCH(A2,C:C,0))-C2)/2))^2))

This formula will calculate the distance between the zip code in cell A2 and all other zip codes in column A. You can then drag the formula down to calculate the distance for each zip code pair.

Displaying Results in a Table

To display the results in a table, you can use conditional formatting to highlight the distances between specific zip codes. Here's how:

  1. Select the range containing the distance calculations.
  2. Click on "Conditional Formatting" in the "Home" tab, then select "New Rule."
  3. Choose "Use a formula to determine which cells to format."
  4. Enter the formula to highlight the distances between specific zip codes (e.g., =A1=$A$2 to highlight distances from the first zip code).
  5. Choose the formatting style, then click "OK."

This will highlight the distances between the specified zip codes in the table.

Now that you know how to calculate miles between zip codes in Excel, you can streamline your distance calculations for various applications, such as route planning, delivery management, or sales territory analysis. Happy calculating!