ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBa Locate Nearest point (https://www.excelbanter.com/excel-programming/389460-vba-locate-nearest-point.html)

[email protected]

VBa Locate Nearest point
 
hello every one

i m working with GPS Coordinates [cartesian coordinates]

i want to locate nearest point at present m using this formula to
locate nearrest point provided by Mr. Joel afew days back it worked
fine

Sub sortdistance()

LastRowA = Cells(Rows.Count, "A").End(xlUp).Row
LastRowE = Cells(Rows.Count, "E").End(xlUp).Row

For i = 1 To LastRowA
X = Cells(i, "A")
Y = Cells(i, "B")

For j = 1 To LastRowE
distance = Sqr((X - Cells(j, "E")) ^ 2 + (Y - Cells(j, "F")) ^
2)
If j = 1 Then
shortX = Cells(j, "E")
shortY = Cells(j, "F")
shortdistance = distance
Else
If distance < shortdistance Then
shortX = Cells(j, "E")
shortY = Cells(j, "F")
shortdistance = distance
End If
End If
Next j

Cells(i, "C") = shortX
Cells(i, "D") = shortY
Next i

End Sub


but i want to knw is there anyother way "more presice n accurate" to
locate nearest point

hope sumbody wud find time to help me out
many thanx in advance



All times are GMT +1. The time now is 01:10 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com