I am trying to find the nearest distance between many points. I have a set of about 300 coordinates that I am comparing to a list of about 4k coordinates. I am using the formula:

=IFERROR(ACOS(COS(RADIANS(90-VLOOKUP(V2,dist,4,FALSE)))*COS(RADIANS(90-O2))+SIN(RADIANS(90-VLOOKUP(V2,dist,4,FALSE)))*SIN(RADIANS(90-O2))*COS(RADIANS(VLOOKUP(V2,dist,5,FALSE)-P2)))*3959,99999999999)

The cells are explained below:

=IFERROR(ACOS(COS(RADIANS(90-LATITUDE 1)))*COS(RADIANS(90-LATITUDE 2))+SIN(RADIANS(90-LATITUDE 1)))*SIN(RADIANS(90-LATITUDE 2))*COS(RADIANS(LONGITUDE 1)-LONGITUDE 2)))*3959,99999999999)

This seems to work fine if comparing the list of 4k against the 300 but if I flip it around it just returns somewhat random numbers mostly 1 and 6, I assume this is somehow limited to the first x number of references? Is there another formula I can run or should I do this outside of excel?

Thanks!