Hello,

I am trying to write a vba function that finds the smallest distance between two large lists of gps coordinates. I already have a basic formula for calculating each of these, but I need to find this efficient function for determining the next closest gps coordinate and by how much. I have done a little bit of vba programming, though I have done more java in the past. I know I will need some type of loop where it looks to determine whether the newly calculated value is smaller than the current running minimum and if not, skip to the next one. I have some rough "pseudocode" of what i'm looking for.

minDistance(range,originalCoords)
define min double = 0
begin loop
dist = originalCoords - nextCoords \\The actual calculation is a little more
if dist < min \\complicated but it should work
dist = min
loop
end loop

I know there's probably a lot missing, including some reference that stops the loop when it hits the last set of coordinates to calculate and something to return the min value. The value nextCoords would be my next listed coordinates to calculate the distance between from the original. Also, I have one cell for latitude and one for longitude, if that is any help.
Any feedback and help would be greatly appreciated!
Thanks!

P.S. if this is listed on another forum topic already, let me know and I will go to there for help!