How to Check if a Number is Between a Range in Excel
In this article
You can check if a number falls between a specific range in Excel by using the logical function IF combined with comparison operators. This function returns a specific value or text if the number is within the range, and a different value if it is outside.
What You'll Need
- A computer with Microsoft Excel installed (2010 or later versions). The steps below are for Windows and macOS, though the interface is nearly identical.
- Two numbers that define your range (e.g., a minimum value and a maximum value).
- A target number or a cell reference containing the number you want to test.
Step-by-Step
- Open your Excel spreadsheet. Locate the cell where you want the result of the check to appear. This is where the "Yes/No" or specific value will show up.
- Click on the cell. This selects the active cell where you will type the formula.
- Type the
IFfunction. Start by typing=IF(into the cell. The IF function is the standard way to perform logical tests in Excel. - Enter the logical test. Type the condition you want to check. For example, if you want to check if a number in cell
A1is between10and50, type:A1>=10. This checks if the value is greater than or equal to the lower bound. - Add the AND function. To ensure the number is also below the upper limit, type
AND(immediately after the logical test. Now your formula looks like this:=IF(AND(A1>=10. - Enter the upper bound. Add the upper limit of your range, followed by a closing parenthesis. For our example, it would be:
A1<=50). The full logical test inside the IF function is nowAND(A1>=10, A1<=50). This ensures the number is both greater than or equal to 10 AND less than or equal to 50. - Define the "True" value. After the closing parenthesis of the logical test, type a comma. This separates the test from the value to return if the test is true. For example, type
"Yes"to return the text "Yes" if the number is in range. - Define the "False" value. Type another comma and then the value to return if the number is not in the range. For example, type
"No". Your formula should look like this:=IF(AND(A1>=10, A1<=50), "Yes", "No"). - Press Enter. Pressing the Enter key will calculate the formula. If the number in cell A1 is 25, the cell will display "Yes". If the number is 5 or 60, it will display "No".
Common Mistakes
Using the AND function is a common source of errors when checking for a range. A frequent mistake is to write the logical test as IF(A1>=10 AND A1<=50, ...). This is technically valid in some versions of Excel if the parentheses are placed correctly, but it can be confusing and is not the standard way to write the formula. The more readable and standard approach is to wrap the entire condition with AND( and ), as shown in the steps above.
Another common error is confusing the order of the numbers in the comparison. If you are checking if a number is between 10 and 50, you must check for A1>=10 and A1<=50. If you accidentally type A1<=10 and A1>=50, you will be looking for numbers that are both less than or equal to 10 and greater than or equal to 50, which is impossible. Excel will return a result of FALSE for all numbers, which will be incorrect.
Tips
It is best practice to use cell references for your range values instead of typing them directly into the formula. This makes your spreadsheet easier to update. For example, if your minimum value is in cell B1 and your maximum value is in cell B2, and your target number is in cell A1, your formula would look like this: =IF(AND(A1>=B1, A1<=B2), "Yes", "No"). This way, you can simply change the values in cells B1 and B2, and the formula will automatically update to check the new range.
For very complex conditions, you can nest multiple IF functions together. For example, you might want to check if a number is in one range and return a specific tier, and if it is in another range and return a different tier. However, for basic range checking, the combination of IF and AND is sufficient and provides the most clarity.
Troubleshooting
If the formula is not working as expected, the first thing to check is the type of data in the cells. If a cell contains text (even if it looks like a number), Excel will not be able to perform mathematical comparisons. For example, if cell A1 contains the text "10" instead of the number 10, the formula =IF(AND(A1>=10, A1<=50), "Yes", "No") will return #VALUE!. To fix this, select the cell and use the Data tab on the ribbon, then click the Text to Columns button. Click Finish on the first two dialogs. This will force Excel to recognize the data as a number.
If you see a #NAME? error, it usually means that you have misspelled a function name. Double-check that you have typed IF and AND correctly and that there are no extra spaces in the formula. If you are using a very old version of Excel, it may not support the AND function. In that case, you can use the * (asterisk) operator to combine the conditions, but it is much harder to read. For example, you could write: =IF((A1>=10)*(A1<=50), "Yes", "No"). This multiplies the two Boolean values, which will be 1 (True) if both are true, or 0 (False) if either is false.
If the formula returns a result that is clearly wrong, check the order of parentheses. The logical test inside the IF function must be enclosed in its own set of parentheses. A common error is to place the closing parenthesis for the logical test in the wrong place, which can cause the entire formula to be interpreted incorrectly. Make sure the structure is: =IF(AND(A1>=10, A1<=50), "Yes", "No"). The first closing parenthesis ends the AND function, and the second closing parenthesis ends the IF function.
Frequently Asked Questions
Can I check if a number is between two dates?
Yes, the same logic applies to dates. You can use the IF and AND functions to check if a date falls within a specific range. For example, =IF(AND(A1>=DATE(2023,1,1), A1<=DATE(2023,12,31)), "Within Year", "Outside Year"). Excel stores dates as serial numbers, so they can be compared using standard mathematical operators.
What if I want the range to be exclusive (not including the endpoints)?
To exclude the endpoints, simply change the comparison operators from = (greater than or equal to) to > (greater than) for the lower bound, and from = (less than or equal to) to < (less than) for the upper bound. For example, =IF(AND(A1>10, A1<50), "Yes", "No").
How do I highlight cells that are between a range?
You can use the Conditional Formatting feature to highlight cells automatically. Select the range of cells you want to check. Go to the Home tab on the ribbon, click Conditional Formatting, and choose New Rule. Select Use a formula to determine which cells to format. In the formula box, type =AND(A1>=10, A1<=50) (adjusting A1 to your top-left cell in the selection). Click Format and choose a fill color, then click OK twice.
Is there a shorter way to write this formula?
There is a function called IFS available in newer versions of Excel (2019 and later) that can simplify the formula. It checks conditions in order and returns the value for the first true condition. However, for a simple between-range check, the IF and AND combination is the most widely supported and easiest to understand.
What does the VLOOKUP function have to do with this?
You can technically use VLOOKUP to find a value in a table that is between two numbers, but it is much more complex and requires a lookup table with the ranges defined. The IF and AND approach is much more direct and easier to set up for a simple check.