deusextra
05-09-2013, 05:38 AM
Hello.
I'm looking to devise a method of using VBA to match x and y co-ordinates to the nearest match.
E.g.
Match the following co-ordinates to the most similar:
x = 59, y = 42
a) x = 52, y = 47
b) x = 51, y = 49
c) x = 58, y = 43
In this case c would be the nearest match.
Can anyone suggest a way to do this on Excel using VBA or any other method?
Thanks!
deusextra
05-09-2013, 08:04 AM
I know the algorithm I need to write...
X and Y co-ordinates are both defined by a number between 0 and 999,999.
I need to find all X co-ordinates within 100 of the given X co-ordinate.
From these results I then need to find the nearest Y co-ordinate.
This is done by finding the lowest (absolute value of given Y co-ordinate minus each of the remaining individual Y values).
When this is found the corresponding unique identifier for the pair of co-ordinates identified is returned.
An example would be:
I'm given the co-ordinates X(250,000), Y(220,000)
The following subset is returned (within 100 of given X co-ordinate)
ID1: X(250,040), Y(120,000)
ID2: X(250,020), Y(320,000)
ID3: X(250,050), Y(215,000)
Then the absolute value between given and found Y co-ordinates would be
120,000 - 220,000 = ABS(-100,000)
320,000 - 220,000 = ABS(100,000)
215,000 - 220,000 = ABS(-5,000)
Therefore, based on the rules of the algorithm the result given would be
ID3: X(250,050), Y(215,000)
Does anyone know how to translate this into code?
Since this is an Excel forum why not posting a sample Excel file ?
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.