Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Match Index with Tolerances

Match Index with Tolerances

Match Index with Tolerances


I'd like to set up a function that compares the locations in the left box with the Master locations in the right box. The function will return the Master location if a match is found.

I've managed to break down the locations by X and Y coordinates.

The test would be something like IF Dist < Tolerance THEN Returns corresponding master location. The function would test all of the master locations.

Dist = SQRT ( |X1-X2|^2 + |Y1-Y2|^2 )

Any help would be much appreciated.

RE: Match Index with Tolerances



   A      B              C       D         E
MASTER			tol	0.5	
x	y		x2	y2	mtch
2.683	19.24		2.437	19.16	2.683:19.24
3.043	22.16		3.015	22.07	3.043:22.16
4.998	13.35		4.998	13.26	4.998:13.35


The ranges in MASTER are named x & y

The funcion to calculate mtch, in a standard module


Function mtch(x2 As Single, y2 As Single, tol As Single)
    Dim rx As Range
    Dim x1 As Single, y1 As Single
    Dim dist As Single
'Dist = SQRT ( |X1-X2|^2 + |Y1-Y2|^2 )
    For Each rx In [x]
        x1 = rx.Value
        y1 = rx.Offset(0, 1).Value
        dist = ((x1 - x2) ^ 2 + (y1 - y2) ^ 2) ^ 0.5
        If dist < tol Then Exit For
    mtch = x1 & ":" & y1
End Function 

Use the mtch function as you would any other function...

E12: =mtch(C12,D12,tol)


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Match Index with Tolerances

Thanks for the really helpful post, SV.

However, I'm getting a #VALUE error when attempting to replicate it. Do you need to add into the function code something that defines the 'tol'?

RE: Match Index with Tolerances

tol is the cell containing 0.5. I have that cell named tol.

Making prolific use of Named Ranges is a wise and beneficial practice.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Match Index with Tolerances

Why do you need to use the ABS function? A number squared is always a positive number.

RE: Match Index with Tolerances

You are correct. Wasn’t thinking.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Match Index with Tolerances

Note, if you have more than one match, the code given by skipVought would only return the first match. This might occur for example if you have a larger tolerance compared to the spacing of points. Two closely spaced points would only return the first match which may or may not be the correct point.

It would be pretty easy to extend the code given to return all matches as an array which is then written to the sheet. Or alternatively return the point with the least distance.

RE: Match Index with Tolerances

In that case, the OP ought to post test data and expected results that illustrate that condition.


glassesJust traded in my OLD subtlety...
for a NUance!tongue

RE: Match Index with Tolerances

I actually want it to return the first match in the master list, so no problems there.

Got it to work fine, that's for the help SV.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Research Report: Augmented Reality for Maintenance, Repair and Overhaul (MRO)
The term Industry 4.0 denotes a cluster of technologies that’s poised to fundamentally reshape manufacturing and bring about a new industrial revolution. These include 3D printing (AM), the Industrial Internet of Things (IIoT), artificial intelligence (AI) and mixed reality technologies, more commonly known as virtual reality (VR) and augmented reality (AR). Download Now
Research Report: The Next Product You Design Might Be a Service Thanks to the IoT
For this report, the editors of engineering.com interviewed companies on the leading edge of implementing products as a service with a view to describing and categorizing the types of products that can be delivered as a service and the technologies that make it possible—one company in high-tech manufacturing, another who helps ensure access to clean water in developing nations, and a third in the mass transportation industry. Download Now

Close Box

Join Eng-Tips® Today!

Join your peers on the Internet's largest technical engineering professional community.
It's easy to join and it's free.

Here's Why Members Love Eng-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close