LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Excel VBA locate nearest point

wrote in message
ups.com...
HI everyone


d = ((x2-x1)^2+(y2-y1)^2) should be minimum , but i m unable to
program it correctly


very simple example, what about:
--------------------8<---------

Const rownum1 = 10 'rows of column1
Const rownum2 = 20 'rows of column2
Const min0 = 1000 'starting minimum, but enough big to be bigger than final

Sub distance1()
Dim i As Integer, j As Integer, d As Double, dmin As Double, rmin As
Integer
With ActiveSheet
For i = 1 To rownum1
dmin = min0
rmin = -1
For j = 1 To rownum2
d = d1(.Cells(i, 1), .Cells(j, 5), .Cells(i, 2), .Cells(j,
6))
If d < dmin Then
rmin = j
dmin = d
End If
Next
.Cells(i, 7).Value = rmin
.Cells(i, 8).Value = dmin
.Cells(i, 3).Value = .Cells(rmin, 5)
.Cells(i, 4).Value = .Cells(rmin, 6)
Next
End With
End Sub

Function d1(x1 As Double, x2 As Double, y1 As Double, y2 As Double) As
Double
d1 = Sqr((x1 - x2) ^ 2 + (y1 - y2) ^ 2)
End Function



 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to locate a point on excel graph? logetic Charts and Charting in Excel 6 April 26th 23 03:45 AM
How do i locate the point of intersection of two lines graphs Nana Adwoa Charts and Charting in Excel 4 April 2nd 23 07:58 PM
Data point on line is not over the point/tick in X axis... TomCat Charts and Charting in Excel 2 September 6th 07 01:36 PM
Rounding to the nearest quarter point? George Excel Discussion (Misc queries) 3 June 10th 06 10:12 PM
Find the nearest point to 1000 rows where "amounts" balance and apply special formatting to that row Paul Excel Programming 4 October 14th 05 05:02 PM


All times are GMT +1. The time now is 09:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"