Ensure that your latitude and longitude values are in the correct units (degrees for the second formula or radians for the first one) for the expression you are using, and the procedure should work as expected.

Can you provide sample data that does not work?

Answer from Vahid Ghafarpour on learn.microsoft.com
🌐
MrExcel
mrexcel.com › forums › question forums › excel questions
Calculating distance between two latitude longitude points | MrExcel Message Board
May 4, 2006 - Or alternatively you could just use Pythagarus Method (Which will probably be close enough) i.e. distance = square-root ( (Xb-Xa)2 + (Yb - Ya)2 ) Or as I have it in an Excel Formula =IF(AL34="",0,(SQRT((VLOOKUP(LEFT(AL34,4),'Postcode ...
🌐
Reddit
reddit.com › r/excel › calculate distance using latitude and longitude excel
r/excel on Reddit: calculate distance using latitude and longitude excel
September 14, 2022 - It allows distance calculation for any address combinations including latitude and longitude. And you have the option to use miles or km as the distance unit. ... I literally just did this. Do you need “straight line” distance or road distance? ... =ACOS(COS(RADIANS(90-Lat1)) * COS(RADIANS(90-Lat2)) + SIN(RADIANS(90-Lat1)) * SIN(RADIANS(90-Lat2)) * COS(RADIANS(Long1-Long2))) * 6371 · but if you have others method tell me (looking for distane not road map) ... Need help finding the distance between two coordinates on the Earth.
Discussions

Excel formula to calculate the distance between multiple points using lat/lon coordinates - Stack Overflow
I'm currently drawing up a mock database schema with two tables: Booking and Waypoint. Booking stores the taxi booking information. Waypoint stores the pickup and drop off points during the journey, More on stackoverflow.com
🌐 stackoverflow.com
excel - Find Distance between different coordinates - Stack Overflow
I have Location data (latitude and longitude) of 1000's of locations and need to compute the distance between each of them taken two combinations at a time. Example: Let's just say I have four More on stackoverflow.com
🌐 stackoverflow.com
How can I calculate the distance between two points using Latitude and Longitude?
u/PercivalFailed - Your post was submitted successfully. Once your problem is solved, reply to the answer(s) saying Solution Verified to close the thread. Follow the submission rules -- particularly 1 and 2. To fix the body, click edit. To fix your title, delete and re-post. Include your Excel version and all other relevant information Failing to follow these steps may result in your post being removed without warning. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/excel
16
6
May 21, 2025
Performing Distance Calculation using Excel? - Geographic Information Systems Stack Exchange
Is there a way (preferably in Excel) to calculate the distance (based on lat, lon) between two lists of points? My end goal would be, for example, to have a list of Starbucks and a list of McDona... More on gis.stackexchange.com
🌐 gis.stackexchange.com
🌐
BatchGeo
blog.batchgeo.com › home › latitude and longitude in excel: calculate distance, convert degrees, and geocode addresses
Calculate Distance, Convert Degrees, and Geocode Addresses
April 17, 2026 - Figure: You only have to enter that formula into EXCEL ONE time. Figure: The 4476 number is the distance in Nautical Miles. The decimals are pretty much useless since you know it’s an approximation. Geocoding is the conversion of street addresses to latitude and longitude data that can be mapped.
🌐
Contextures
contextures.com › formulas › distance
How to Calculate Distance in Excel Latitude and Longitude
July 1, 2023 - ... '*************************...============================ Public Function distVincenty(ByVal _ lat1 As Double, ByVal lon1 As Double, _ ByVal lat2 As Double, _ ByVal lon2 As Double) As Double 'INPUTS: Latitude and Longitude ...
🌐
The Bricks
thebricks.com › resources › how-to-calculate-distance-between-two-latitude-and-longitude-excel
How to Calculate the Distance Between Two Latitudes and Longitudes in Excel
Δφ is the difference in latitude, and Δλ is the difference in longitude. R is the Earth’s radius (mean radius = 6,371 km). d will give you the distance between the two points. This formula uses trigonometric functions to calculate the great-circle distance—the shortest distance between two points on the surface of a sphere. This might sound like a lot of work, but Excel can handle all these calculations for you.
Find elsewhere
🌐
The Bricks
thebricks.com › resources › guide-how-to-calculate-distance-between-two-latitude-and-longitude-excel-using-ai
How to Calculate Distance Between Two Latitude and Longitude in Excel Using AI
February 20, 2025 - You can do this using Excel's `RADIANS()` function. For example, `RADIANS(A2)` converts the latitude in cell A2 into its radian equivalent. The Vincenty formula looks complex, but it’s just a series of calculations that use the cosine, sine, ...
🌐
Support Your Tech
supportyourtech.com › home › excel › how to calculate distance between two latitude and longitude in excel
How to Calculate Distance Between Two Latitude and Longitude in Excel
July 26, 2024 - Learn to calculate the distance between two latitude and longitude points in Excel using the Haversine formula and essential trigonometric functions.
🌐
Blogger
bluemm.blogspot.com › 2007 › 01 › excel-formula-to-calculate-distance.html
BlueMM: Excel formula to calculate distance between 2 latitude, longitude (lat/lon) points (GPS positions)
January 6, 2007 - But it wasn't working, because my GPS points (Lat/Lon) were in decimal degrees, not radians. So I used the formula I found at Latitude And Longitude In Excel (under the "Great Circle Distances" section) by Chip Pearson:
🌐
Excel Tips
excel.tips.net › T003275_Calculating_the_Distance_between_Points.html
Calculating the Distance between Points - Microsoft Excel Tips
October 22, 2022 - As you can tell, the formula to calculate distances is quite long. You may find it easier to develop your own user-defined function that will do the calculation for you. The following function takes four values (the two pairs of latitudes and longitudes, in degrees), and then returns a result in nautical miles:
🌐
Geocodio
geocod.io › geocodio - the delightfully boring geocoder › calculate distance between two addresses or coordinates in a spreadsheet
Calculate Distance Between Two Addresses or Coordinates in a Spreadsheet | Geocodio
We're using Excel and Google Sheets, but a similar approach should also work in Numbers. This guide assumes you're using Geocodio for your calculations and that latitude/longitude are in separate columns. Since Geocodio provides decimal degrees, all examples use decimal degrees.
Top answer
1 of 2
3

Alternatively, you can create a VBA function and then loop through your table.

Add this code to a Module in the VBA editor:

CopyPublic Function DistBetweenCoord(Lat1 As Double, Long1 As Double, Lat2 As Double, Long2 As Double)
    'Cell Formula
    'ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371

    With WorksheetFunction
        A = Cos(.Radians(90 - Lat1))
        B = Cos(.Radians(90 - Lat2))
        C = Sin(.Radians(90 - Lat1))
        D = Sin(.Radians(90 - Lat2))
        E = Cos(.Radians(Long1 - Long2))

        DistBetweenCoord = .Acos(A * B + C * D * E) * 6371
    End With
End Function

Now you can access this through code or in cell. Here is an example of in-cell:

Copy=DistBetweenCoord(C1,D1,C2,D2)

Here is how to loop through all possible combinations in another Sub. Output is in immediate window.

CopySub CalcAllDistances()
    With Worksheets("Sheet1")
        For i = 1 To 4
            For j = i To 4
                If i <> j Then
                    Debug.Print .Cells(i, 2) & " to " & .Cells(j, 2) & ": " & DistBetweenCoord(.Cells(i, 3), .Cells(i, 4), .Cells(j, 3), .Cells(j, 4))
                End If
            Next j
        Next i
    End With
End Sub


EDIT - To change output to Sheet2 try the following:

CopySub CalcAllDistances()
    Dim wks_Output As Worksheet
    Set wks_Output = Worksheets("Sheet2")

    Dim OutputRow As Long: OutputRow = 1

    With Worksheets("Sheet1")
        For i = 1 To 4
            For j = i To 4
                If i <> j Then
                    wks_Output.Cells(OutputRow, 1).Value = .Cells(i, 2) & " to " & .Cells(j, 2)
                    wks_Output.Cells(OutputRow, 2).Value = DistBetweenCoord(.Cells(i, 3), .Cells(i, 4), .Cells(j, 3), .Cells(j, 4))
                    OutputRow = OutputRow + 1
                End If
            Next j
        Next i
    End With
End Sub

2 of 2
2

I would use a matrix. Create a sheet (like 'GeocodeList' or something) for the geocodes, like your city|lat|lon in the question. Then create a sheet (like 'Distances') for a matrix, where the column and row labels are the city names. Then you can parameter your excel formula using V.LOOKUPs that look up exact codes from GeocodeList.

The formula would look like this (X is row number, Y is column letter.):

Copy=ACOS(COS(RADIANS(90-VLOOKUP($A(X); GEOCODETABLE, LATCOLINDEX, 0)))
*COS(RADIANS(90-VLOOKUP((Y)$1; GEOCODETABLE; LATCOLINDEX, 0)))
+SIN(RADIANS(90-VLOOKUP($A(X); GEOCODETABLE, LATCOLINDEX, 0)))
*SIN(RADIANS(90-VLOOKUP((Y)$1; GEOCODETABLE; LATCOLINDEX, 0)))
*COS(RADIANS(VLOOKUP($A(X); GEOCODETABLE, LATCOLINDEX, 0)-VLOOKUP((Y)$1; GEOCODETABLE; LONCOLINDEX, 0))))
*6371

So basically the VLOOKUP automatically fetches your parameters, and you can extend the formula for the whole matrix.

🌐
Reddit
reddit.com › r/excel › how can i calculate the distance between two points using latitude and longitude?
r/excel on Reddit: How can I calculate the distance between two points using Latitude and Longitude?
May 21, 2025 -

I have a list of locations and their latitude and longitudes. I want to compare them to a specific point and use a formula to output their distances from that point in terms of how many miles East and North of that point they are, not in a straight line beween them.

So I'd have my origin point and point A. Lines 2 and 3 would look something like this:

Name of Origin point | latitude O | longitude O | 0 | 0

Name of Point A | latitude A | longitude A | X (number of miles) | Y (number of miles)

What formulas would I use in columns D and E to calculate these distances?

Top answer
1 of 11
9
This may be slightly more complicated than you're expecting, and I apologize for not directly providing any formulas as I'm on mobile. The easy one is your northing. Latitude lines are all parallal, and what you could do is convert your start and end points from coordinate to radians, relative to the equator. Then multiply that difference by the radius of the earth. To be hyper-technical, the earth is not a sphere, but an oblate spheroid. Without the context of the distances you're covering, I would be shocked if that ended up making a practical difference. Easting is slightly more complicated, since the distance between longitude lines gets smaller the closer to the poles you are (I will assume you're referring to distances in the northern hemisphere). Again, the effect of this will depend on the distances being considered. The calculation of this distance would again be coordinate to radian, multiply by radius, however, this circle would only be the radius of the earth if the coordinates were on the equator. You would need a calculation to determine the radius of the horizontal section of the earth that that northing coordinate makes. You will get different answers depending on if you calculate this distance at the start or end northing. You'll have to use your judgement on which is appropriate for your use case. For the actual calculations, assuming you want these constrained to their own column and not have to create multiple dummy columns, the LET() function is your friend here.
2 of 11
6
Like this? Haversine formula seems to work... || || |Place|Latitude|Longitude|Distance KM|Distance Mi| |Toronto|43.651070|-79.347015|510.6768877|317.3234442| |Montreal-EST|45.630001|-73.519997||| Here you go: https://pastebin.com/raw/Cs72CSAJ
Top answer
1 of 2
17

Given a list of geographic coordinate pairs, you can implement the Haversine formula directly in Excel.


The simplest way to use this (or a more accurate, but I think it's not your case) formula consists into press Alt+F11 to open the VBA Editor, click Insert --> Module and then (copy and) paste e.g. the code kindly suggested by blah238.

Public Function getDistance(latitude1, longitude1, latitude2, longitude2)  
earth_radius = 6371  
Pi = 3.14159265  
deg2rad = Pi / 180  

dLat = deg2rad * (latitude2 - latitude1)  
dLon = deg2rad * (longitude2 - longitude1)  

a = Sin(dLat / 2) * Sin(dLat / 2) + Cos(deg2rad * latitude1) * Cos(deg2rad * latitude2) * Sin(dLon / 2) * Sin(dLon / 2)  
c = 2 * WorksheetFunction.Asin(Sqr(a))  

d = earth_radius * c  

getDistance = d  

End Function

There will be a new custom getDistance function (unit = kilometer) available in your spreadsheet which accepts four parameters, i.e. the two pairs of coordinates, as follow:

getDistance(latitude1, longitude1, latitude2, longitude2)

where latitude1, longitude1, latitude2, longitude2 should be replaced by their relative cell references.

2 of 2
3

A more accurate way is to use Vicenty's formula. It is based on an ellipsoid instead of a sphere. However, the previous answer will do the job if you work in a city (differences can be neglected in your case). I've found an excel vb code here just in case.

Note that if you work in a city, using "bird flight" distances could be misleading. It would be better to use network distances. A compromise is to use "Manhattan distance"

🌐
SpreadsheetWeb
spreadsheetweb.com › home › a use case of excel’s lambda function in spreadsheetweb: calculating distance by latitude and longitude
A Use Case of Excel's LAMBDA Function in SpreadsheetWeb: Calculating Distance by Latitude and Longitude
November 22, 2022 - Let's create our custom function as described above. The distance formula needs 4 arguments, if we use a static value for the radius of earth, e.g., 6,371 km.
🌐
Oreate AI
oreateai.com › blog › calculating-distance-between-latitude-and-longitude-in-excel › c9113bbc8a37e540bdd1d3c092c7651e
Calculating Distance Between Latitude and Longitude in Excel - Oreate AI Blog
December 22, 2025 - For example, if you want to find out how far apart Beijing and Shanghai are straight-line-wise; just plug their latitudes and longitudes into this process as described above—convert them into radians then use this formula—and voila!
🌐
Quora
quora.com › Is-there-a-formula-available-in-Excel-that-would-take-the-latitude-and-longitude-of-two-points-and-compute-the-distance-between-them
Is there a formula available in Excel that would take the latitude and longitude of two points and compute the distance between them? - Quora
Answer (1 of 3): =ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))) *6371 Assumes… * Distance is across the surface — not straight line through the planet.
🌐
ExcelDemy
exceldemy.com › home › excel formulas › how to calculate distance between two gps coordinates in excel
How to Calculate Distance Between Two GPS Coordinates in Excel - ExcelDemy
April 15, 2024 - Here, the new DistCalc function which was VBA coded estimates the distance between the two points and can be called up by Excel similarly to any other function you use.