compare all distances and match with the closest item

kamiltuncer

New Member
Joined
Jul 26, 2011
Messages
2
Hello everybody

Consider I have something like attached.

What I need to do is; compare distances between A1-B1, A1-B2, A1-B3... etc. and match A1 with the closest one (in this case it is B1)

I have X-Y coordinates for all items here.

I attached a screenshot of a sample excel file to make it more explanatory.

I did this with calculating differences between X & Y coordinates and apply pythagoras theorem but the problem is I have to write very long formulas in each cell.

I believe very small VBA code can solve this but Im zero with VBA.

Can anybody help about this issue please

Dropbox - Untitled.png

Dropbox - Untitled2.png

Thanks
 
Last edited:

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
try this with a slim down version of your data


Excel 2012
ABCDEFGH
1XYXY
2A1378B7B11645
3A21440B4B2630
4A34034B5B31426
5A44710B7B41442
6A53627B10B54343
7A64849B8B62248
8A71434B10B7235
9A84413B7B84747
10A93537B5B95044
11A102528B10B101929
Sheet1
Cell Formulas
RangeFormula
D2{=INDEX($F$2:$F$11,MATCH(MIN((($B2-$G$2:$G$11)^2+($C2-$H$2:$H$11)^2)^0.5),(($B2-$G$2:$G$11)^2+($C2-$H$2:$H$11)^2)^0.5,0))}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,713
Messages
6,174,041
Members
452,542
Latest member
Bricklin

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