Formula Errors

Return 0, 1, or 2 for Number Ranges in Excel

Jason MillerJason Miller Nov 12, 2026 869 views

Question details

Create a formula that returns 1 for values below 30, 0 for values from 30 through 160, and 2 for values above 160.

Return 0, 1, or 2 Based on a Number Range in Excel
Product
Microsoft Excel
Device & OS
not provided
Scenario
The user needs to classify a number in a worksheet cell into one of three numeric result groups.
Observed behavior
The desired result is 1 when the input is less than 30, 0 when it is 30 to 160 inclusive, and 2 when it is greater than 160.
Before you start

Confirm that the input value is in cell A1, or replace A1 in the formulas with the cell that contains your number. Make sure the cell contains a numeric value rather than text.

Solution 1Recommended

Use a nested IF formula for three number ranges

Use this compatible option when you need a formula that works in most Excel versions.

The formula tests the lowest range first. If the value is not below 30, it checks whether the value exceeds 160; otherwise, it returns 0 for the inclusive middle range.

1
Select the result cell

Click the cell where you want the classification result to appear, such as B1.

2
Enter the nested IF formula

Type =IF(A1<30,1,IF(A1>160,2,0)) and press Enter.

3
Fill the formula down if needed

Drag the fill handle from the selected result cell down the column to apply the formula to additional rows.

Use a nested IF formula for three number ranges
Range boundaries included: A value of 30 or 160 returns 0 because only values below 30 and above 160 receive the other results.
Formula classification in WPS Spreadsheets

Classify Number Ranges with IF Formulas in WPS Spreadsheets

WPS Spreadsheets lets you use the same nested IF logic to label values by range. Enter the formula in a result column, then fill it down to classify every number in your table efficiently.

  1. 1. Open the worksheet in WPS Spreadsheets: Open your .xlsx or .xls file in WPS Office and select the worksheet containing the values.
  2. 2. Select the first result cell: Click the cell beside the first input value, such as B1 when the source number is in A1.
  3. 3. Enter the range formula: Type =IF(A1<30,1,IF(A1>160,2,0)) in the formula bar and press Enter.
  4. 4. Apply the formula to remaining rows: Drag the fill handle at the lower-right corner of the result cell down the column.
Use nested IF formulas to return 1, 0, or 2 for defined value ranges.Work with Microsoft Excel .xlsx and .xls spreadsheets.Apply formulas across large columns with AutoFill.Use a familiar spreadsheet interface for Excel-style formulas.
microsoft office alternative - wps office

Frequently Asked Questions

What result does the formula return when the value is exactly 30?

It returns 0. In =IF(A1<30,1,IF(A1>160,2,0)), 30 is not less than 30 and is not greater than 160, so Excel uses the final 0 result.

What result does the formula return when the value is exactly 160?

It returns 0. The condition A1>160 is false for 160, so the value remains in the middle range.

How can I use a different input cell instead of A1?

Replace every A1 reference with your input cell reference. For example, use =IF(C2<30,1,IF(C2>160,2,0)) when the value is in C2.

Why does my formula return an error for a blank or text cell?

Check that the referenced cell contains a number. If necessary, handle blanks first with a formula such as =IF(A1="","",IF(A1<30,1,IF(A1>160,2,0))).