Find the nearest location to another location

lucky13pierre

New Member
Joined
Feb 9, 2023
Messages
1
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
In sheet 1 I've got a list of the locations I need to allocate people to. I've got a latitude and longitude location for each one. On sheet 2 I've got a list of the people with their locations in latitude and longitude. Example below

SHEET 1
Post Code Lat Lon Allocated to
SW1X 51.498 -0.153

SHEET 2
Name Post Code Lat Lon
Pierre RM20 51.478 0.289


There are about a couple of hundred locations and around a dozen people. I need to put a formula in the 'Allocated to' column to find out which of my colleagues are closest to each location easily. I've got a formula [=3960*ACOS(COS(RADIANS(90-C3))*COS(RADIANS(90-C4))+SIN(RADIANS(90-C3))*SIN(RADIANS(90-C4))*COS(RADIANS(D3-D4)))] to find out distance, and can use the =min() function if I was putting each post code in one at a time but that would be very time consumung.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I think you will find the task be more complex than determining which person is nearest the location.

Anyway, this would be my approach...
1) Create a table with the locations in vertical and the list of the persons, with their coordinates, in horizontal (as in the image)

2) Calculate the distance between the sites and each of the people:
In F5
Code:
=3960*ACOS((SIN(RADIANS($B5))*SIN(RADIANS(F$2))+(COS(RADIANS($B5))*COS(RADIANS(F$2))*COS(RADIANS(F$3-$C5)))))
(this is a simplified version of your formula)
Copy F5 to the right for as many persons are listed

Copy the first line of formulas down for all the locations

3) Use conditional format to highlight the best match for each of the lines:
Select the whole distance table, from F5 to Qxxx (if 12 persons are listed)
Set a conditional format, "Using a formula", using the following formula:
Code:
=F5=MIN($F5:$Q5)
Assign a background color Green and complete the formatting

Now you should see for each site who is the nearest person

4) Populate column D with the "Allocated to" name:
In D5 use the formula
Code:
=INDEX($F$1:$J$1,MATCH(MIN($F5:$Q5),$F5:$Q5,0))

Copy D5 down

That should give for each site who is the nearest "as the crow flies"

Now the simpe task :eek:is review the result to consider the street distance non the "crow fly distance" and to balance the workload...



MULTI_C30207.xlsm
ABCDEFGHIJ
1LouisPhilMichelMarieDenise
2Lat44,567844,678945,012344,987645,0023
3Long3,45672,38763,00123,67893,3322
4LocationLatLongNearest
5Site145,66662,1234Michel 99,98 69,47 62,16 88,97 74,55
6Site244,43212,2345Phil 60,98 18,65 55,01 80,67 66,78
7Site346,11113,3333Denise 106,83 109,11 77,63 79,43 76,63
8
9
Foglio3
Cell Formulas
RangeFormula
F5:J7F5=3960*ACOS((SIN(RADIANS($B5))*SIN(RADIANS(F$2))+(COS(RADIANS($B5))*COS(RADIANS(F$2))*COS(RADIANS(F$3-$C5)))))
D5:D7D5=INDEX($F$1:$Q$1,MATCH(MIN($F5:$Q5),$F5:$Q5,0))
 

Attachments

  • GEODIS_Immagine 2023-02-09 194239.jpg
    GEODIS_Immagine 2023-02-09 194239.jpg
    59.6 KB · Views: 9
Last edited:
Upvote 0

Forum statistics

Threads
1,215,088
Messages
6,123,057
Members
449,091
Latest member
ikke

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