Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later versions of Excel, click here: Determining If a Value is Out of Limits.

Determining If a Value is Out of Limits

Written by Allen Wyatt (last updated April 13, 2019)
This tip applies to Excel 97, 2000, 2002, and 2003


2

Jennifer has two numbers that she needs to compare in a formula. If the second number is within 5% (plus or minus) of the first number, it is considered within limits. If the second number is outside of this range, then she needs the formula to return something such as "out of limits."

There are a number of different ways you could approach your formula. Let's assume that your first number is in cell A1 and that the number you want to compare to it is in cell B1. One method is to use the IF function to do your testing:

=IF((A1-B1)>(A1*0.05),"out of limits",
IF((B1-A1)>(A1*0.05),"out of limits",
"within limits"))

This works fine, but the formula is a bit long. You can add the OR function to your formula to make it quite a bit shorter:

=IF(OR(B1<A1*0.95,B1>A1*1.05),"out of limits","within limits")

You could make the formula shorter still by skipping the OR function and simply doing a comparison on the absolute difference between the values:

=IF(ABS((B1-A1)/A1)<=0.05,"within limits","out of limits")

Since there is division happening in this formula, it is possible that you could get an error if the value in A1 is 0. To avoid this potential problem, the formula should be modified slightly:

=IF(A1=0,"unknown",IF(ABS((B1-A1)/A1)<=0.05,
"within limits","out of limits"))

If the requirement is for the values to be "within 5% of each other," the calculation is slightly more complex:

=IF(ABS(B1-A1)/MAX(ABS(B1),ABS(A1))>0.05,
"out of limits","within limits")

In this case, the MAX function is used to determine the larger of the two values in A1 and B1. It must test the absolute values of A1 and B1 because the MAX function returns the value nearest to zero if both numbers are negative.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3803) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) here: Determining If a Value is Out of Limits.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Removing Return Addresses

Word allows you to print return addresses on your envelopes. You may run across a scenario where the return address is ...

Discover More

Displaying a Value and a Percentage in a Single Cell

Sometimes it can be helpful to show both a numeric value and a percentage in the same cell. This can be done through ...

Discover More

Making a Customized Theme Available to Others

Microsoft Office applications (including Word) allow you to work with collections of common formatting specifications, ...

Discover More

Best-Selling VBA Tutorial for Beginners Take your Excel knowledge to the next level. With a little background in VBA programming, you can go well beyond basic spreadsheets and functions. Use macros to reduce errors, save time, and integrate with other Microsoft applications. Fully updated for the latest version of Office 365. Check out Microsoft 365 Excel VBA Programming For Dummies today!

More ExcelTips (menu)

Solving Simultaneous Equations

One branch of mathematics allows you to work with what are called "simultaneous equations." Working with this type of ...

Discover More

Maintaining Text Formatting in a Lookup

Want to maintain the formatting used in one cell when you use formulas to reference that text in another cell? The answer ...

Discover More

Totaling Across Worksheets

Want to sum the values in the same cell on a range of worksheets? It's not as easy as summing a range on the same ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two minus 0?

2019-10-10 12:23:00

Adrian Dent

I was trying your formula, however, it gives all my values as over budget when I want to see if the value is over or under within a range of 15% of the second value :

=IF(ABS(B1-A1)/MAX(ABS(B1),ABS(A1))>0.15,
"over budget","under budget")

I'm testing two percentages (Actual Expenditure vs Budgeted Expenditure)

If the Value of Cell B is Equal to Cell A then Good, but if Cell B is outside of a range of 20% of the value of Cell B compared with Cell A then flag as Under if it's greater than 20% or Flag Red if it's greater than 20%

A (budget) | B (time elapsed) | C
21.37% | 62.11% Under Budget (is what I'd expect - we should have spent 62% but we've only spent 21% so far)
131.44% | 26.58% Over Budget
1.96% | 14.81% GOOD (within Tolerance)
8.93% | 80.56% Under Budget
87.65% | 6.13% Over Budget
50% | 60% GOOD
60% | 50% GOOD

Is there a way I could do this to allow a tolerance either side of Cell B, within a single formula.

thanks in advance, Adrian


2019-09-03 00:51:26

Phuah

I had facing some problem with the similar formula for =IF(OR(B1<A1*0.95,B1>A1*1.05),"out of limits","within limits"). I had created my sheet with this formula =IF((OR($B121:$B131<$B131*$D$7, $B121:$B131>$B131*$D$8)),"1","0") but it facing error on excel with #value after creating 12 cells with this formula.

Is it limitation in excel application bugs?


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.