← All how-to recipes

How to test if a value is between two numbers

✓ Verified in LibreOffice 25.8.7.3 ✓ Verified in Google Sheets (2026-08-30)

An in-range check — because 10<=A2<=20 doesn't work the way you'd hope.

The formula

AppFormulaNotes
Excel (desktop)=IF(AND(A2>=10,A2<=20),"In range","Out")There's no BETWEEN operator; AND of two comparisons is the idiom.
Google Sheets=IF(AND(A2>=10,A2<=20),"In range","Out")Identical.
LibreOffice Calc=IF(AND(A2>=10,A2<=20),"In range","Out")Identical.

How it works

The chained form 10<=A2<=20 doesn't error — worse, it evaluates left-to-right into TRUE<=20, which is always TRUE, so everything passes the test. AND(A2>=10,A2<=20) is the correct spelling: 15 clears both bounds. An arithmetic alternative some prefer: =MEDIAN(10,A2,20)=A2 is TRUE exactly when A2 is within [10,20] — and MEDIAN(10,A2,20) by itself doubles as a clamp.

Verified, not just documented

We ran =IF(AND(A2>=10,A2<=20),"In range","Out") in LibreOffice 25.8.7.3 (headless, with forced recalculation) and it returned In range — exactly the expected result. We then ran the same formulas in Google Sheets, executed 2026-08-30: a formula-only workbook goes into Google Drive, which converts it to a Sheet and recalculates every formula with Google’s own engine, and comes back out as .xlsx carrying the values Google computed. It returned In range for the worked example, the same value LibreOffice produced. Both engines’ numbers on this page are executed results. The Excel formula follows Microsoft’s official documented syntax — we do not run desktop Excel.

Functions used

IF · AND — see full Excel, Google Sheets & LibreOffice compatibility for each.

Related recipes

Related comparisons