Another way:
Function FindMinDist(lat1 As Double, lon1 As Double, r As Range) As Double
Const pi As Double = 3.14159265358979
Const D2R = pi / 180#
Dim iRow As Long
Dim dMin As Double
Dim dAng As Double
dMin = 1.79E+308
For iRow = 1 To r.Rows.Count
dAng = CentralAngle(lat1, lon1, r(iRow, 1).Value2, r(iRow, 2).Value2)
If dAng < dMin Then dMin = dAng
Next iRow
FindMinDist = dMin
End Function
Function CentralAngle(ByVal lat1 As Double, ByVal lon1 As Double, _
ByVal lat2 As Double, ByVal lon2 As Double) As Double
' shg 2008-1111
' Returns central angle between two points in RADIANS using Vincenty formula
Const pi As Double = 3.14159265358979
Const D2R As Double = pi / 180#
Dim dLon As Double
Dim x As Double
Dim y As Double
' convert angles from degrees to radians
lat1 = D2R * lat1
lat2 = D2R * lat2
dLon = D2R * (lon2 - lon1) ' delta lon
x = Sin(lat1) * Sin(lat2) + Cos(lat1) * Cos(lat2) * Cos(dLon)
y = Sqr((Cos(lat2) * Sin(dLon)) ^ 2 + (Cos(lat1) * Sin(lat2) - Sin(lat1) * Cos(lat2) * Cos(dLon)) ^ 2)
CentralAngle = WorksheetFunction.Atan2(x, y)
End Function
By passing the range containing the other lat-longs, Excel sees a dependency and will automatically recompute when the data changes. Example usage:
=FindMinDist(D2, E2, D4:E392)
The value returned is in radians, which means you can multiply by the earth radius in your preferred units (meters, miles, nautical miles, ...) to get linear (great circle) distance.
Bookmarks