Excel - As-the-crow-flies distance function
The demo file offers three ways to calculate the as-the-crow-flies
distance, the shortest distance between two geographical locations specified by latitude and longitude
Download demo file
- Regular formula. It is a pretty long one, that might be difficult to link to its inputs and/or copy across.
- VBA - User Defined Function (UDF) GlobeDistance. Much easier to read and link. But will execute slower. You can set its argument InMiles to TRUE/FALSE to retrieve distance in miles/kilometers.
- LAMBDA function L_GlobeDistance. LAMBDA functionality is new in Office365/Excel 2021 (still being rolled out). It enables you to directly create a function within Name Manager.
(32kB - downloaded
Given the following input fields (in degrees): From latitude (cell A4), From longitude (cell B4), To latitude (cell C4), To longitude (cell D4), InMiles (cell E4) the formula is
Dependent on your MS Excel setting you may have to use comma or semicolon in your formula.
User Defined Function GlobeDistance: VBA code to be put in a module
In MS Excel, press Alt+F11 to open the Visual Basic Editor (Windows). Via top menu: Insert → Module. Copy the MS Excel VBA code below into the module.
Note: in general, a user defined function will execute slower than a standard function, which can become a disadvantage in case of a large amount of formulas.
LAMBDA Function L_GlobeDistance