Return 0, 1, or 2 for Number Ranges in Excel
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.

- 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.
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.
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.
Click the cell where you want the classification result to appear, such as B1.
Type =IF(A1<30,1,IF(A1>160,2,0)) and press Enter.
Drag the fill handle from the selected result cell down the column to apply the formula to additional rows.

Use IFS in Excel 365
Use IFS when you prefer a more readable formula with separate condition-and-result pairs.
Use SWITCH with TRUE for ordered conditions
Use SWITCH(TRUE,...) in Excel 365 when you want to evaluate multiple logical tests in sequence.
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. Open the worksheet in WPS Spreadsheets: Open your .xlsx or .xls file in WPS Office and select the worksheet containing the values.
- 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. Enter the range formula: Type =IF(A1<30,1,IF(A1>160,2,0)) in the formula bar and press Enter.
- 4. Apply the formula to remaining rows: Drag the fill handle at the lower-right corner of the result cell down the column.

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))).




