# How to find the nearest location by coordinates in Excel

Work out every distance and look up the smallest: `=LET(dist,SQRT((B2:B7-G1)^2+(C2:C7-I1)^2),XLOOKUP(MIN(dist),dist,A2:A7))`.

**Excel:** `=LET(dist,SQRT((B2:B7-G1)^2+(C2:C7-I1)^2),XLOOKUP(MIN(dist),dist,A2:A7))` (Excel 2021, 2024 and Microsoft 365)

**Google Sheets:** the same formula works.

## Example

Sample data (row 1 is the header):

| A | B | C | D | E | F | G | H | I |
| --- | --- | --- | --- | --- | --- | --- | --- | --- |
| Warehouse | East (mi) | North (mi) |  |  | Customer east | 34 | Customer north | 18 |
| Northgate | 12 | 41 |  |  | Nearest warehouse |  |  |  |
| Riverside | 38 | 9 |  |  |  |  |  |  |
| Hillcrest | 27 | 25 |  |  |  |  |  |  |
| Bayview | 55 | 30 |  |  |  |  |  |  |
| Westfield | -8 | 14 |  |  |  |  |  |  |
| Lakeshore | 31 | 52 |  |  |  |  |  |  |

Formula in G2: `=LET(dist,SQRT((B2:B7-G1)^2+(C2:C7-I1)^2),XLOOKUP(MIN(dist),dist,A2:A7))`

Result: Riverside

## How it works

For each warehouse, `SQRT((B2:B7-G1)^2+(C2:C7-I1)^2)` is the straight-line distance to the customer, by Pythagoras. LET names that list `dist`, MIN finds the shortest, 9.8 miles, and XLOOKUP returns the warehouse it belongs to, Riverside, just ahead of Hillcrest at 9.9.

## Other ways

- `=INDEX(A2:A7,MATCH(MIN((B2:B7-G1)^2+(C2:C7-I1)^2),(B2:B7-G1)^2+(C2:C7-I1)^2,0))`: Every version (Ctrl+Shift+Enter in Excel 2019 and earlier). Squared distances rank the same way, so SQRT can be skipped.

## Common mistakes

- Latitude and longitude aren't miles: a degree of longitude shrinks toward the poles. Multiply the longitude difference by `COS(RADIANS(latitude))` before squaring, or use the haversine formula for long distances.
- Straight-line distance ignores roads. For delivery times, use a routing service.

## Questions

**How do I return the distance too?**

Return `MIN(dist)` from the same LET in the next cell.

**How do I list the three nearest?**

Sort by distance: `=TAKE(SORTBY(A2:A7,SQRT((B2:B7-G1)^2+(C2:C7-I1)^2)),3)`.

Every formula and result on this page was checked by running it in the Spreadsheet Practice formula engine on 2026-10-30.

Source: https://spreadsheetpractice.com/formulas/nearest-location-by-coordinates
