Jonathan
Jonathan

Reputation: 2847

Check if number in range

How do I check if a number is in a range of numbers (not a range of cells). For example in many programming languages I can write a >= 1 && a <= 7. How do I express this in Google Sheets?

Upvotes: 4

Views: 14080

Answers (2)

Matěj Kř&#237;ž
Matěj Kř&#237;ž

Reputation: 1228

Use ISBETWEEN() function:

ISBETWEEN function checks whether a provided number is between two other numbers either inclusively or exclusively.

Usage in your case (a === A1 cell):

=ISBETWEEN(A1; 1; 7)

If a is in the range 1 - 7 it returns TRUE.
You can also set optional settings for inclusive/exclusive lower/upper value - by default is set to inclusive for both.

Parts of a ISBETWEEN function:

ISBETWEEN(value_to_compare, lower_value, upper_value, lower_value_is_inclusive, upper_value_is_inclusive)
Part Description
value_to_compare The value to test as being between lower_value and upper_value.
lower_value The lower boundary of the range of values that value_to_compare can fall within.
upper_value The upper boundary of the range of values that value_to_compare can fall within.
lower_value_is_inclusive [optional] Whether the range of values includes the lower_value. By default this is TRUE
upper_value_is_inclusive [optional] Whether the range of values includes the upper_value. By default this is TRUE

For more information see: https://support.google.com/docs/answer/10538337?hl=en

Upvotes: 4

JDro04
JDro04

Reputation: 670

IF(AND(logical_expression1, logical_expression2), value_if_true, value_if_false)

EDIT: IF(AND(a1 >=1, a1 <= 7),value_if_true, value_if_false)

https://support.google.com/docs/table/25273?hl=en

Upvotes: 4

Related Questions