Shortest distance between Lat/Longs with condition

excelnovicetx

New Member
Joined
Jun 1, 2018
Messages
2
Hi all,

This has been bothering me for the last few days. What I am looking to do is find the shortest distance in miles between two lat long points, (which I have figured out thanks to posts on this site). However, I also want to limit the result to just the nearest lat long point associated with a specific company in another column.

On my main tab:
Lat/Long 1 are in columns L and M
Company by Lat/Long is located in Column O

Recent Activity Tab:
Lat/Long 2 can be found in C in rows 3:650 and D in rows 3:650
Company by lat/long is located in Column E in rows 3:650

I then want to only find the shortest distance by Recent Activity Column E as it relates to Column O on my main tab

I have tried wrapping the working formula (below) in a match, an index, index match, indeex match match, and an If statement, etc and have not been able to make it work.

{=INDEX(ACOS(COS(RADIANS(90-L3))*COS(RADIANS(90-'Recent Activity'!$CN$3:$CN$650))+SIN(RADIANS(90-L3))*SIN(RADIANS(90-'Recent Activity'!$C$3:$C$650))*COS(RADIANS(M3-'Recent Activity'!$D$3:$D$650)))*3958.75,MATCH(SMALL((ABS('Recent Activity'!$C$3:$C$650-L3)^2+ABS('Recent Activity'!$D$3:$D$650-M3)^2)^(0.5),1),(ABS('Recent Activity'!$C$3:$C$650-L3)^2+ABS('Recent Activity'!$D$3:$D$650-M3)^2)^(0.5),0))}

The result should be the shortest number of miles between two lat longs only between those where the companies match.

Thanks for the help!
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Welcome to the forum.

It's not really possible for most people to look at your post and propose a solution unless they have some data on which to conduct experiments. I've composed some sample data that uses NHL distances between arenas. After revieweing it, please tell use what you would like to do to that sample data to meet your needs.


Book1
ABCDEFGHIJKLM
1TeamNameCity/AreaArenaCoord_hmsCoor_decLatitudeLongitude
2AnaheimAnaheim DucksAnaheim, CAHonda Center3348'28?N 11752'36?W??33.80778N 117.87667W?33.8078-117.8767
3ArizonaArizona CoyotesGlendale, AZGila River Arena3331'55?N 11215'40?W??33.53194N 112.26111W?33.5319-112.2611
4BostonBoston BruinsBoston, MATD Garden4221'58.69?N 713'44.02?W??42.3663028N 71.0622278W?42.3663-71.0622
5BuffaloBuffalo SabresBuffalo, NYFirst Niagara Center4252'30?N 7852'35?W??42.87500N 78.87639W?42.8750-78.8764
6CalgaryCalgary FlamesCalgary, ABScotiabank Saddledome5102'15?N 11403'07?W??51.03750N 114.05194W?51.0375-114.0519
7CarolinaCarolina HurricanesRaleigh, NCPNC Arena3548'12?N 7843'19?W??35.80333N 78.72194W?35.8033-78.7219
8ChicagoChicago BlackhawksChicago, ILUnited Center4152'50?N 8740'27?W??41.88056N 87.67417W?41.8806-87.6742
9ColoradoColorado AvalancheDenver, COPepsi Center3944'55?N 1050'27?W??39.74861N 105.00750W?39.7486-105.0075
10ColumbusColumbus Blue JacketsColumbus, OHNationwide Arena3958'9.42?N 830'22.00?W??39.9692833N 83.0061111W?39.9693-83.0061
11DallasDallas StarsDallas, TXAmerican Airlines Center3247'26?N 9648'37?W??32.79056N 96.81028W?32.7906-96.8103
12DetroitDetroit Red WingsDetroit, MIJoe Louis Arena4219'31?N 833'5?W??42.32528N 83.05139W?42.3253-83.0514
13EdmontonEdmonton OilersEdmonton, ABRexall Place5334'17?N 11327'22?W??53.57139N 113.45611W?53.5714-113.4561
14
53
54dist (km)AnaheimArizonaBostonBuffaloCalgaryCarolinaChicagoColoradoColumbusDallasDetroitEdmonton
55Anaheim05214152351319413558278313213155195831672225
56Arizona5210370530731952306323439462689143927262230
57Boston415237050642336498413692842103424939853333
58Buffalo3513307364202789786731220147219273472788
59Calgary19411952336427890327322461438268724672532285
60Carolina35583063984786327301027234359616928163330
61Chicago278323431369731224610270147544612923852305
62Colorado13219462842220114382343147501873106618581664
63Columbus31552689103447226875964461873014692622736
64Dallas195814392493192724671692129210661469016072661
65Detroit3167272698534725328163851858262160702559
66Edmonton22252230333327882853330230516642736266125590
Sheet2
Cell Formulas
RangeFormula
B55=ACOS(COS(RADIANS(90-INDEX($G$2:$G$32,MATCH($A55,$A$2:$A$32,0)))) *COS(RADIANS(90-INDEX($G$2:$G$32,MATCH(B$54,$A$2:$A$32,0)))) +SIN(RADIANS(90-INDEX($G$2:$G$32,MATCH($A55,$A$2:$A$32,0)))) *SIN(RADIANS(90-INDEX($G$2:$G$32,MATCH(B$54,$A$2:$A$32,0)))) *COS(RADIANS(INDEX($H$2:$H$32,MATCH($A55,$A$2:$A$32,0))-INDEX($H$2:$H$32,MATCH(B$54,$A$2:$A$32,0)))))*6371
 
Upvote 0
Thanks for the reply:

Main Tab


[TABLE="width: 500, align: center"]
<tbody>[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]Column L (Lat)
[/TD]
[/TR]
[TR]
[TD="width: 70"]31.6639[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Column M (Long)

[TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"]-93.7729[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Column O (Company)

Delta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]31.7509[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"]-93.5517[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Delta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]31.7219[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"]-93.6876[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Beta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]31.7801[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"]-93.6366[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Gamma[/TD]
[/TR]
[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]32.4647[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"]-93.9937[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Beta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]32.4502[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"]-93.9938[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Delta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]32.3631[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"][TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"]-93.975[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Gamma[/TD]
[/TR]
[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]32.4324[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"]-93.6563[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Beta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="width: 70"]32.4205[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 82"]
<tbody>[TR]
[TD="width: 82"]-93.8403[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Gamma[/TD]
[/TR]
</tbody>[/TABLE]

Recent Activity Tab:

[TABLE="width: 500, align: center"]
<tbody>[TR]
[TD]Column C (Lat)[/TD]
[TD]Column D (Long)[/TD]
[TD]Column E (Company)[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]32.2222[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.5752[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Gamma[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]32.12232[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.5868[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Gamma[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]32.25154[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.4116[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Beta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]32.25085[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.4709[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Beta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]32.27449[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.6285[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Beta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]32.24886[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.8857[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Gamma[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]32.16435[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.8551[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Delta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]31.91699[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.5922[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Delta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]32.10503[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.3515[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Delta[/TD]
[/TR]
[TR]
[TD][TABLE="width: 70"]
<tbody>[TR]
[TD="class: xl95, width: 70"][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]32.21104[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][TABLE="width: 64"]
<tbody>[TR]
[TD="width: 64, align: right"]-93.9701[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD]Gamma[/TD]
[/TR]
</tbody>[/TABLE]


I can figure out the closest distance to each one, but want to limit to when only the closest one where the company is the same.

Does this help?

I added the underlined text to the formula this morning and it seems to help but also returns several "False" answers.

{=IF('Recent Activity'!$E$3:$E$651=$O2,INDEX(ACOS(COS(RADIANS(90-L3))*COS(RADIANS(90-'Recent Activity'!$CN$3:$CN$650))+SIN(RADIANS(90-L3))*SIN(RADIANS(90-'Recent Activity'!$C$3:$C$650))*COS(RADIANS(M3-'Recent Activity'!$D$3:$D$650)))*3958.75,MATCH(SMALL((ABS('Recent Activity'!$C$3:$C$650-L3)^2+ABS('Recent Activity'!$D$3:$D$650-M3)^2)^(0.5),1),(ABS('Recent Activity'!$C$3:$C$650-L3)^2+ABS('Recent Activity'!$D$3:$D$650-M3)^2)^(0.5),0))}
 
Upvote 0

Forum statistics

Threads
1,224,826
Messages
6,181,192
Members
453,021
Latest member
pingpong7117

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