## Summary

To test if a value is within expected tolerance or not, you can use a formula based on the IF function and the ABS function. In the example shown, the formula in E5, copied down, is:

``````=IF(ABS(B5-C5)<=D5,"OK","Fail")
``````

When the value in column B is within +/- .005 of 0.250 (from column C), the formula returns "OK". If not, the formula returns "Fail".

## Generic formula

``=IF(ABS(actual-expected)<=tolerance,"OK","Fail")``

## Explanation

In this example the goal is to check if values in column B are within a tolerance of .005. If a value is within tolerance, the formula should return "OK". If the value is out of tolerance, the formula should return "Fail". The expected value is listed in column C, and the allowed tolerance is listed in column D. The solution is based on the IF function together with the ABS function.

### Core logic

To check if a value is within a given tolerance, we can use a simple logical test like this:

``````=ABS(actual-expected)<=tolerance // logical test
``````

Inside the ABS function, the actual value is subtracted from the expected value. The result may be positive or negative, depending on the actual value, so the ABS function is used to convert the result to a positive number: negative values become positive and positive values are unchanged. The result from ABS is compared to the allowed tolerance with the logical operator less than or equal (<=).  The expression returns TRUE when a value is less than or equal to the allowed tolerance, and FALSE if not.

### IF function

To complete the solution, we need to place the generic logical expression  above into the IF function and providing values for a TRUE and FALSE result. The first step is to revise the generic expression above to use worksheet references:

``````ABS(B5-C5)<=D5 // logical test
``````

Then, we drop the expression into the IF function as the logical_test argument:

``````=IF(ABS(B5-C5)<=D5,"OK","Fail") // final formula
``````

When the logical test returns TRUE, IF returns "OK". When the logical test returns FALSE, IF returns "Fail". These messages can be customized as needed.

### List all values within tolerance

The basic concept explained above can be extended to list values within tolerance or out of tolerance with the FILTER function. Author ### Dave Bruns

Hi - I'm Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.