Explanation

At the core, this formula runs two tests on a value like this:

=D5>MIN(B5,C5) // is D5 greater than smaller?
=D5<MAX(B5,C5)) // is D5 less than larger?

In the first expression, the value is compared to the smaller of the two numbers, determined by the MIN function.

In the second expression, the value is compared to the larger of the two numbers, determined by the MAX function.

The AND function will return TRUE only when the value is greater than the smaller number and less than the larger number.

Include boundaries

To include the boundary numbers (num1 and num2), adjust the logical operators like this:

=AND(D5>=MIN(B5,C5),D5<=MAX(B5,C5))

Now the AND function will return TRUE only when the value is greater than or equal to the smaller number and less than or equal to the larger number.

Simple version

The formula in the example is more complex because there is no assumption that num1 is less than num2 (or vice versa). If it’s safe to assume that num1 is less than num2 , the formula can be simplified like this:

=AND(value>num1,val<num2)

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 .