# Determining If a Value is Out of Limits

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.

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.

Related Tips:

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

 *Name: Email: Notify me about new comments ONLY FOR THIS TIP Notify me about new comments ANYWHERE ON THIS SITE Hide my email address *Text: *What is 5+3 (To prevent automated submissions and spam.)

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)

# Our Company

Sharon Parq Associates, Inc.

# Our Sites

Tips.Net

Beauty and Style

Cars

Cleaning

Cooking

ExcelTips (Excel 97–2003)

ExcelTips (Excel 2007–2016)

Gardening

Health

Home Improvement

Money and Finances

Organizing

Pests and Bugs

Pets and Animals

WindowsTips (Microsoft Windows)

WordTips (Word 97–2003)

WordTips (Word 2007–2016)

Excel Products

Word Products

# Our Authors

Author Index

Write for Tips.Net