简体   繁体   中英

Check if number in range - Google sheets

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?

I tried to apply this solution , but how would that formula work in order to handle multiple ranges? For example:

C12 = 5

I want to check if C12 is either in ranges:

  • 1-10
  • 11-25
  • 26-50

I'm trying the following but it's not working:

=IFS(AND(C12>=1,C12<=10),"1-10",(AND(C12>=11,C12<=25),"11-25","26-50"))

IFS need pairs and it will short circuit at the first TRUE so we can shorten it to:

=IFS(C12<=10,"1-10",C12<=25,"11-25",TRUE,"26-50")

Or we can use CHOOSE:

=CHOOSE(MATCH(C12,{1,11,26}),"1-10","11-25","26-50")

How about:

=IF(AND(C12>=1,C12<=10),"1-10",IF(AND(C12>=11,C12<=25),"11-25",IF(AND(C12>=26,C12<=50),"26-50","NONE")))

在此处输入图片说明

same in Google-Sheets:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM