Sub CalculD()
' Dist=6371*acos(sin(Lat1)sin(Lat2)+cos(Lat1)cos(Lat2)cos(Long2-Long1))
Dim PI, i%, j%, Lon, Lat, Dist
Application.ScreenUpdating = False
PI = Application.PI()
Coord = Range("B2:C" & Range("B65500").End(xlUp).Row)
Coordref = Range("I3:J" & Range("I65500").End(xlUp).Row)
For i = 1 To UBound(Coord)
Lon = 2 * PI * Coord(i, 1) / 360: Lat = 2 * PI * Coord(i, 2) / 360: DistMin = 9 ^ 9
For j = 1 To UBound(Coordref)
Dist = 6371 * Application.Acos(Sin(Lat) * Sin(2 * PI * Coordref(j, 2) / 360) + Cos(Lat) * Cos(2 * PI * Coordref(j, 2) / 360) * Cos(Lon - 2 * PI * Coordref(j, 1) / 360))
If Dist < DistMin Then
DistMin = Dist
IndexP = j
End If
Next j
Cells(i + 1, "D") = Coordref(IndexP, 1)
Cells(i + 1, "E") = Coordref(IndexP, 2)
Cells(i + 1, "F") = DistMin
Next i
End Sub