How to Check If a Value Lies Between Two Numbers and Return a Result in Excel

Understanding the IF-THEN Formula

In a nutshell, Excel’s IF-THEN formula allows you to create conditional logic within a worksheet. It checks whether a specified condition is true or false and performs a specific task based on that condition.


Scenario – Employee Age List Dataset

Suppose we have an Employee Age List dataset with employee names and their corresponding ages in cells B4:C13.

excel formula if between two numbers then


Method 1 – Using the Excel AND Function

Let’s start with the simplest approach: using the AND function to check if an employee’s age falls between 25 and 30 years. Follow these steps:

  • Go to cell D5.
  • Enter the following formula:

=AND(C5>=$G$6,C5<=$G$5)

Here:

  • C5 represents the employee’s age.
  • $G$6 is the upper limit (30 years).
  • $G$5 is the lower limit (25 years).

Note: Use absolute cell references by pressing the F4 key on your keyboard.

Formula Breakdown:

The formula AND(C5>=$G$6, C5<=$G$5) checks whether both arguments are TRUE. If they are, it returns TRUE. Specifically:

  • C5>=$G$6 is the logical1 argument.
  • C5<=$G$5 is the logical2 argument.

Since both arguments evaluate to TRUE, the function returns the output TRUE.

Using AND Function for If-Then Formula Between Two Numbers

  • Use the Fill Handle tool to copy the formula down to other cells.

Using AND Function

Your result should resemble the image below:

Using AND Function

Read More: How to Make Yes 1 and No 0 in Excel


Method 2 – Using IF and AND Functions to Determine If a Value Lies Between Two Numbers and Return Text

  • Start by moving to cell D5.
  • Enter the following expression:

=IF(AND(C5>=$G$6,C5<=$G$5),"Yes","No")

In this formula:

  • C5 represents the employee’s age.
  • $G$6 is the upper limit (30 years).
  • $G$5 is the lower limit (25 years).

Formula Breakdown:

    • AND(C5>=$G$6, C5<=$G$5) checks whether both arguments are TRUE. If they are, it returns TRUE.
    • The entire formula evaluates whether the age in cell C5 falls between the upper and lower limits.
    • If TRUE, it returns “Yes”; otherwise, it returns “No.”
  • The output will be either “Yes” or “No.”

Utilizing IF and AND Functions for If-Then Formula Between Two Numbers

Your result should resemble the image below:

Using IF and AND Function

Read More: How to Check If a Value Is Between Two Numbers in Excel


Method 3 – Applying Excel Conditional Formatting

Another approach involves using Conditional Formatting to highlight cells where a value lies between two numbers. Here’s how:

  • Go to cell D5 and enter the formula:

=AND(C5>=$G$6,C5<=$G$5)

Again, C5, $G$6, and $G$5 represent the age, upper limit, and lower limit, respectively.

Applying Conditional Formatting for If-Then Formula Between Two Numbers

  • Select the range of cells D5:D13.
  • Under the Home tab, click the Conditional Formatting drop-down and choose New Rule.

Applying Conditional Formatting

  • In the New Formatting Rule wizard, select Use a formula to determine which cells to format.
  • Enter the same formula:

=AND(C5>=$G$6,C5<=$G$5)

  • Click the Format box to specify the cell color.

Applying Conditional Formatting

  • In the Format Cells wizard, go to the Fill tab and choose a color (e.g., Light Green).
  • Click OK.

Applying Conditional Formatting

The result will highlight cells where the age falls within the specified limits.

Applying Conditional Formatting for If-Then Formula Between Two Numbers

Read More: How to Use IF Function with Multiple Conditions in Excel


Method 4 – Returning TRUE/FALSE If a Value Lies Between Two Numbers Using Excel AND, MIN, and MAX Functions

Here, we’ll combine the AND, MIN, and MAX functions to check if a third number lies between these two numbers.
Let’s consider the Numbers List dataset in the B4:D13 cells. Here, the dataset shows a Start Value, End Value, and Number respectively.

Using AND, MIN, and MAX Functions for If-Then Formula in Excel

  • Start by moving to cell E5.
  • Enter the following expression:

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

In this formula:

  • B5, C5, and D5 represent the start value, end value, and the number, respectively.

Formula Breakdown:

  • AND(D5>=MIN(B5,C5), D5<=MAX(B5,C5)) checks whether both arguments are TRUE. If they are, it returns TRUE.
  • The logical1 argument (D5>=MIN(B5,C5)) checks if the value in cell D5 is greater than or equal to the larger of the two values in cells B5 and C5.
  • The logical2 argument (D5<=MAX(B5,C5)) checks if the value in cell D5 is less than or equal to the smaller of the two values in cells B5 and C5.
  • If both arguments evaluate to TRUE, the function returns TRUE.
    • The output will be either TRUE or FALSE.

Using AND, MIN, and MAX Functions for If-Then Formula in Excel

Your result should resemble the image below:

Using AND, MIN, and MAX Functions for If-Then Formula in Excel


How to Use COUNTIFS Function to Count Between Two Numbers in Excel

If you want to count the number of occurrences between two numbers, you can use the COUNTIFS function. Let’s see it in action:

  • Navigate to cell F6.
  • Enter the following expression:

=COUNTIFS(C5:C13,"<=30",C5:C13,">=25")

Here:

  • C5:C13 represents the range of cells containing employee ages.
  • 30 and 25 are the upper and lower limits, respectively.

Formula Breakdown:

  • COUNTIFS(C5:C13, “<=30”, C5:C13, “>=25”) counts the number of cells that meet specific conditions.
  • The first set of criteria (<=30) counts all age values that are less than or equal to 30.
  • The second set of criteria (>=25) counts values that are greater than or equal to 25.
  • The result shows the number of ages between 25 and 30.
  • Output: 5

Employing COUNTIFS Function to Count Between Two Numbers

Your results should resemble the screenshot below:

Employing COUNTIFS Function to Count Between Two Numbers


Download Practice Workbook

You can download the practice workbook from here:


Related Articles


<< Go Back to Excel IF Function | Excel Functions | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Eshrak Kader
Eshrak Kader

Eshrak Kader is a dedicated professional with a BSc. Degree in Naval Architecture and Marine Engineering from Bangladesh University of Engineering and Technology. He boasts a rich background in Microsoft Office Suite, and over the past year, he has authored over 120 insightful articles for the ExcelDemy. Currently, Eshrak leads a team of 5 in the ExcelDemy Video project and enjoys problem-solving and making videos on Excel. Eshrak’s passion for continuous learning underscores his commitment to excellence in... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo