Hi All,

Trying to create an easy to use function in VBA from the complicated formula below.

but i cant seem to get it working? Any help be much appreciated!

=IFERROR(6371*ACOS(COS(RADIANS(90-Lat1)) *COS(RADIANS(90-Lat2)) +SIN(RADIANS(90-Lat1)) *SIN(RADIANS(90-Lat2)) *COS(RADIANS(Long1-Long2))),0)

Function CROWFLIES(dlat1 As Variant, dlat2 As Variant, dlon1 As Variant, dlon2 As Variant)
       
    Pi = 3.1415
    
    Rads = Pi / 180
    
    Acos1 = Application.WorksheetFunction.Acos(Argument)
    
    Errorcheck = Application.WorksheetFunction.IfError(Arg1, Arg2)

    CROWFLIES = Errorcheck(6371 * (Acos1(Cos(Rads(90 - dlat1))) * (Cos(Rads(90 - dlat2)) + Sin(Rads(90 - dlat1))) * (Sin(Rads(90 - dlat2))) * (Cos(Rads(dlon1 - dlon2)))), 0)
    
End Function