我正在尝试在数字范围之间设置一个包含多个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")))
答案 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函数来获取最接近的匹配。
准备数据范围并命名:'numberRange':
选择范围。转到菜单:数据→命名范围...→定义新命名范围。
使用这个简单的公式:
=VLOOKUP(A2,numberRange,2)
这样您就可以省略错误,并轻松纠正结果。
答案 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)),)), )
=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));)); )
答案 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)))