Comparing Latitude and Longitude to find Closest Distance

one3nine0

Board Regular
Joined
Jul 21, 2014
Messages
127
So i have a table like the one below (but much larger, showing multiple states):

Company IDStateZip CodeLatitudeLongitudeClosest Company ID Distance (miles)
37
AK9950361.1988159
-149.9060107
80AK9951861.17353626
-149.883512
230
AK99654
61.56331423
-149.2925177
353
AK99654
61.57614692
-149.4098359
270
AK
99669

<colgroup><col></colgroup><tbody>
</tbody>
60.50016076
-151.0765804

<colgroup><col></colgroup><tbody>
</tbody>
272AK
99672

<tbody>
</tbody>
60.52622641
-150.7265724

<tbody>
</tbody>
81AK9970164.836296-147.715406

<tbody>
</tbody>


Is there a formula or macro I can use that will give me the shortest distance to the nearest Company ID by Latitude and Longitude in an adjacent column?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi, yes you could use a formula to get the distance.
What would be the point's coordinates to compare with?
 
Upvote 0
So the goal is to take this list, and for each company ID or location to find the nearest Company ID location and report the distance in the blank column.

I cannot find a way to make 1 formula to look and compare all the points to find the closest without having to individually compare each point and then just selecting the lowest value

The current distance formula I am working off of is: =ACOS(COS(RADIANS(90-Lat1)) * COS(RADIANS(90-Lat2)) + SIN(RADIANS(90-Lat1)) * SIN(RADIANS(90-Lat2)) * COS(RADIANS(Long1-Long2))) * 3958.761
 
Upvote 0
Ok, I figured out how use an array to get what I need. I do get num errors with the ACOS function that I am not sure how to solve, and right now i am just performing those by name. Any insight into that would be really helpful
 
Upvote 0
Try =0.621371*(RadiusEarth*((2*ASIN(SQRT((SIN((RADIANS(lat_1)-RADIANS(lat_2))/2)^2)+COS(RADIANS(lat_1))*COS(RADIANS(lat_2))*(SIN((RADIANS(long_1)-RADIANS(long_2))/2)^2))))))
withe the earth radius set at 6371.1 km
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,698
Members
449,117
Latest member
Aaagu

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
Back
Top