Excel Initial bearing

The demo file offers three ways to calculate the initial bearing, the angle between two geographical locations specified by latitude and longitude. This initial bearing is the absolute bearing with reference direction North = 0 degrees. It is calculated in clockwise direction, with values in range [0, 360>. It is referred to as an azimuth by the US Army.
  1. Regular formula. As it is a pretty long one, it might be a bit cumbersome to adjust it and link it to input fields. (It uses MOD to convert a negative degree to a positive, -18° → 342°.)
  2. VBA - User Defined Function (UDF) InitialBearing. Much easier to read and link. But will execute noticeable slower if you use this function in thousands of cells, because programming language VBA is slow. (Unlike Excel function MOD the VBA function MOD always returns a whole number, so it could not be used.)
  3. LAMBDA function L_InitialBearing. LAMBDA functionality exists since Office365/Excel 2021. LAMBDA functions are user defined functions created directly within Excel's Name Manager. Executes fast.

Download demo file  (33kB - downloaded 162 times)

Online version





Regular formula

Dependent on your Excel setting, copy in semicolon or comma version.

Given the following input fields (in degrees): From latitude (cell A4), From longitude (cell B4), To latitude (cell C4), To longitude (cell D4), the formula is



User Defined Function InitialBearing: 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.


LAMBDA Function L_InitialBearing

Dependent on your Excel setting, copy in semicolon or comma version.