Excel Formula: If Greater Than But Less Than


You can use the following formula in Excel to check if the value in a particular cell is greater than one value but less than another value:

=IF(AND(B2>20,B2<30),"Yes", "No")

This particular formula checks if the value in cell B2 is greater than 20 but less than 30 and returns “Yes” or “No” as a result.

The following example shows how to use this formula in practice.

Example: If Greater Than But Less Than Formula in Excel

Suppose we have the following dataset in Excel that shows the number of points scored by basketball players on various teams:

Suppose we would like to check if each value in the Points column is greater than 20 but less than 30.

We can type the following formula into cell C2 to do so:

=IF(AND(B2>20,B2<30),"Yes", "No")

We can then click and drag this formula down to each row in column C:

Excel if greater than but less than

Column C now returns either “Yes” or “No” to indicate if each corresponding value in column B is greater than 20 but less than 30.

For example:

  • The value 22 is greater than 20 but less than 30 so the formula returns Yes.
  • The value 14 is not greater than 20 but less than 30 so the formula returns No.
  • The value 17 is not greater than 20 but less than 30 so the formula returns No.

And so on.

Note: In this example we chose to return the values “Yes” or “No” but you can replace these values with whatever values you’d like to return.

Additional Resources

The following tutorials explain how to perform other common operations in Excel:

Excel: How to Sum If Greater Than Zero
Excel: How to Find First Value Greater than Specific Number
Excel: How to Find Last Value in Column Greater than Zero

4 Replies to “Excel Formula: If Greater Than But Less Than”

  1. Hi,
    My name is Usha,
    I need a formula for my problem.

    example: 1 Size and 1 measuring point for your reference.
    Tolerance: +or-, Actual: xyz, 3 Garment measurements: x,y,z.
    I have approximately 30 Po’s per day, in 1 po I have to measure 7 Sizes x 15 measuring Points x 3 Garments = 315 x 30 Po’s =9450 column entries we cannot recheck the tolerance are +or- or more, so please help me out in this problem.

    1. To address your problem of checking tolerances for garment measurements efficiently, you can create a formula or a systematic approach to streamline the process. Here’s a step-by-step method to achieve this:

      1. **Define the Tolerance Range**: Let’s assume your tolerance range is \( \pm T \).

      2. **Calculate Acceptable Range for Each Measurement**: For each actual measurement \( \text{xyz} \) and each garment measurement \( x, y, z \), calculate the acceptable range.

      \[
      \text{Lower Bound} = \text{xyz} – T
      \]
      \[
      \text{Upper Bound} = \text{xyz} + T
      \]

      3. **Compare Each Measurement Against Tolerance**: Check if each garment measurement falls within the acceptable range. This can be done using the following condition:

      \[
      \text{Lower Bound} \leq \text{Measurement} \leq \text{Upper Bound}
      \]

      4. **Automate the Process**: Given the large number of measurements (9450 per day), it’s essential to automate this process using a spreadsheet (e.g., Excel) or a programming script (e.g., Python).

      ### Excel Formula Approach

      If you are using Excel, you can create a formula to check if each measurement is within the tolerance range. Assume the following:
      – The actual measurement (xyz) is in cell `A1`
      – The tolerance \( T \) is in cell `B1`
      – The garment measurements are in cells `C1`, `D1`, `E1`

      You can use the following formula to check if the measurement in cell `C1` is within the tolerance range:

      “`excel
      =IF(AND(C1 >= ($A$1 – $B$1), C1 <= ($A$1 + $B$1)), "Within Tolerance", "Out of Tolerance") ``` Drag this formula down for all measurements. Repeat this for cells `D1` and `E1` by changing `C1` to `D1` and `E1` respectively. ### Python Script Approach If you prefer using Python, you can write a script to automate this process. Here's an example script: ```python import pandas as pd # Assuming you have a DataFrame 'df' with columns 'Actual', 'Tolerance', and 'Measurements' as a list of lists # Each row in 'df' represents one PO def check_tolerance(actual, tolerance, measurements): lower_bound = actual - tolerance upper_bound = actual + tolerance return ["Within Tolerance" if lower_bound <= m <= upper_bound else "Out of Tolerance" for m in measurements] # Example DataFrame data = { "Actual": [xyz1, xyz2, xyz3], # Replace with actual values "Tolerance": [T1, T2, T3], # Replace with tolerance values "Measurements": [[x1, y1, z1], [x2, y2, z2], [x3, y3, z3]] # Replace with measurement lists } df = pd.DataFrame(data) # Apply the function to each row df['Tolerance Check'] = df.apply(lambda row: check_tolerance(row['Actual'], row['Tolerance'], row['Measurements']), axis=1) # Explode the list to separate rows tolerance_results = df.explode('Tolerance Check') # Save or print the results print(tolerance_results) ``` This script will output a DataFrame where each measurement is checked against the tolerance range, indicating whether it is "Within Tolerance" or "Out of Tolerance". ### Summary By using either the Excel formula or the Python script, you can efficiently handle the large number of measurements and check if they fall within the specified tolerance range. This approach will save time and reduce errors compared to manual checking.

Leave a Reply

Your email address will not be published. Required fields are marked *