Complex Distance Formula

dkoucky

New Member
Joined
Dec 12, 2016
Messages
10
Hi,

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!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

pbornemeier

Well-known Member
Joined
May 24, 2005
Messages
3,890
What do you mean by "flip it around"? Please explain your setup for 4K vs 300 and 300 vs 4K.
 

dkoucky

New Member
Joined
Dec 12, 2016
Messages
10
I think the formula is the great circle but it has been a while since I first used it and I have just been copying it. Do you know how/where I can use it in code? I am not sure if there is a way to host a file on this form I have uploaded the file via zippyshare here: https://www40.zippyshare.com/v/m72PpET4/file.html
 

Watch MrExcel Video

Forum statistics

Threads
1,132,706
Messages
5,654,841
Members
418,155
Latest member
demasisi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top