Hello:
I’m trying to create a VBA function that will return the distance in statute miles between two points expressed in decimal latitude and longitude. So far, I have:
Function Distxx(Lat1, Lon1, Lat2, Lon2)
Distxx = RadiusEarth * ((2 * Application.WorksheetFunction.Asin(Sqr((Sin((Application.WorksheetFunction.Radians(Lat1) - Application.WorksheetFunction.Radians(Lat2)) / 2) ^ 2) + Cos(Application.WorksheetFunction.Radians(Lat1)) * Cos(Application.WorksheetFunction.Radians(Lat2)) * (Sin((Application.WorksheetFunction.Radians(Lon1) - Application.WorksheetFunction.Radians(Lon2)) / 2) ^ 2)))))
End Function
but the formula returns zero for all inputs that I have tried. Can anyone tell me what’s wrong with it?
(And if there is a simpler way to do this, I would love to know what it is.)
Thanks !!
Bookmarks