Google电子表格 - 数字范围之间的多个IF语句

时间:2014-08-31 00:19:49

标签: spreadsheet google-apps

我正在尝试在数字范围之间设置一个包含多个IF语句的公式,但我收到错误“公式解析错误”。

以下是论坛:

=IF((AND(A2>0,A2<500),"Less than 500",
 If(AND(A2>=500,A2<1000),"Between 500 and 1000"),
 If(AND(A2>=1000,A2<1500),"Between 1000 and 1500"),
 If(AND(A2>=1500,A2<2000),"Between 1500 and 2000")))

4 个答案:

答案 0 :(得分:32)

由于嵌套的IF,这有点棘手,但这是我的回答(在Google Spreadsheets中确认):

=IF(AND(A2>=0,    A2<500),  "Less than 500", 
 IF(AND(A2>=500,  A2<1000), "Between 500 and 1000", 
 IF(AND(A2>=1000, A2<1500), "Between 1000 and 1500", 
 IF(AND(A2>=1500, A2<2000), "Between 1500 and 2000", "Undefined"))))

答案 1 :(得分:10)

我建议使用vlookup函数来获取最接近的匹配。

第1步

准备数据范围并命名:'numberRange':

enter image description here

选择范围。转到菜单:数据→命名范围...→定义新命名范围。

第2步

使用这个简单的公式:

=VLOOKUP(A2,numberRange,2)

enter image description here

这样您就可以省略错误,并轻松纠正结果。

答案 2 :(得分:0)

基于VLOOKUP

的独立单元格解决方案

美国语法:

=IFERROR(ARRAYFORMULA(IF(LEN(A2:A),
        IF(A2:A>2000, "More than 2000",VLOOKUP(A2:A,
 {{(TRANSPOSE({{{0;   "Less than 500"},
               {500;  "Between 500 and 1000"}},
              {{1000; "Between 1000 and 1500"},
               {1500; "Between 1500 and 2000"}}}))}}, 2)),)), )

EU语法:

=IFERROR(ARRAYFORMULA(IF(LEN(A2:A);
        IF(A2:A>2000; "More than 2000";VLOOKUP(A2:A;
 {{(TRANSPOSE({{{0;   "Less than 500"}\
               {500;  "Between 500 and 1000"}}\
              {{1000; "Between 1000 and 1500"}\
               {1500; "Between 1500 and 2000"}}}))}}; 2));)); )

替代方法:https://webapps.stackexchange.com/questions/123729/

答案 3 :(得分:0)

比公认的A短,易于扩展,地址为0及以下:

=if(or(A2<=0,A2>2000),"?",if(A2<500,"Less than 500","Between "&500*int(A2/500)&" and "&500*(int(A2/500)+1)))