×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Are you an
Engineering professional?
Join Eng-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*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.

# Match Index with Tolerances

## Match Index with Tolerances

(OP)
Hi,

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

Hi,

Assumptions:

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

#### CODE

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
Next

mtch = x1 & ":" & y1
End Function

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

E12: =mtch(C12,D12,tol)

Skip,

Just traded in my OLD subtlety...
for a NUance!

### RE: Match Index with Tolerances

(OP)
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.

Skip,

Just traded in my OLD subtlety...
for a NUance!

### 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.

Skip,

Just traded in my OLD subtlety...
for a NUance!

### 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.

Skip,

Just traded in my OLD subtlety...
for a NUance!

### RE: Match Index with Tolerances

(OP)
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.

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!