IF和ELSE在Excel中

huangapple go评论62阅读模式
英文:

IF and ELSE in excel

问题

> 输入图像描述

值1    值2    颜色
2     16     =IF(A2>5,"红色", IF(AND(5>A2>1,40>B2>1,"黄色")),IF(AND(5>A2>1,40>B2>60,"红色")),IF(AND(5>A2>1,60>B2>100,"黄色")),"绿色")

我认为其逻辑如下:

如果 "值1" > 5 ---> "红色"

如果 "值1" 在1-5之间且 "值2" 在1-40之间 ---> "黄色"

如果 "值1" 在1-5之间且 "值2" 在40-60之间 ---> "红色"

如果 "值1" 在1-5之间且 "值2" 在60-100之间 ---> "黄色"

否则 ---> "绿色"

我希望根据两个不同列中的两个值显示颜色 "红色"、"黄色" 或 "绿色"。我尝试查找相关信息,但找不到可以使我的公式起作用的东西。希望图片能够解释清楚。

它只显示公式错误,但我无法弄清楚该怎么做...

英文:

> enter image description here

Value1   Value2    Color
2        16        =IF(A2>5,"Red", IF(AND(5>A2>1,40>B2>1,"Yellow")),IF(AND(5>A2>1,40>B2>60,"Red")),IF(AND(5>A2>1,60>B2>100,"Yellow")),"Green)

The logic for which, I believe is:

If "Value1" > 5 ---> "Red"

If "Value1" is between 1-5 and "Value2 " is between 1-40 ---> "Yellow"

If "Value1" is between 1-5 and "Value2 " is between 40-60 ---> "Red"

If "Value1" is between 1-5 and "Value2 " is between 60-100 ---> "Yellow"

Else ---> "Green"

I want the color «red», «yellow» og «green» to be shown in a column based on two values from two different colums. I’ve tried to look it up but I can’t find anything to make my formula work. Hope the picture explains

It only says that the formula is wrong but I can’t figure out what to do…

答案1

得分: 1

=IF(A2>5, "红色", IF(AND(A2>1, B2>1, B2<40), "黄色", IF(AND(A2>1, B2>40, B2<60), "红色", IF(AND(A2>1, B2>60, B2<100), "黄色", "绿色")))

或者使用这个

=IF(OR(B2>=100, A2<=1), "绿色", IF(OR(A2>5, 60>B2>40), "红色", "黄色"))

英文:
=IF(A2&gt;5, &quot;Red&quot;, IF(AND(A2&gt;1, B2&gt;1, B2&lt;40), &quot;Yellow&quot;, IF(AND(A2&gt;1, B2&gt;40, B2&lt;60), &quot;Red&quot;, IF(AND(A2&gt;1, B2&gt;60, B2&lt;100), &quot;Yellow&quot;, &quot;Green&quot;))))

or use this

=IF(OR(B2&gt;=100, A2&lt;=1), &quot;Green&quot;, IF(OR(A2&gt;5, 60&gt;B2&gt;40), &quot;Red&quot;,&quot;Yellow&quot;))

答案2

得分: 0

=IF(AND(A2<=5,B2<100,B2>60),"Yellow",IF(OR(A2>5,AND(B2>=40,B2<60)),"Red","Green"))

(根据您的请求,我只提供代码的翻译部分)

英文:

Try this:

=IF(AND(A2&lt;=5,B2&lt;100,B2&gt;60),&quot;Yellow&quot;,IF(OR(A2&gt;5,AND(B2&gt;=40,B2&lt;60)),&quot;Red&quot;,&quot;Green&quot;))

(Edited as I hadn't realised the mid-range for Value2 in 40-60 was to go red)

Rather than use (to me anyway) the confusing 1&gt;x&gt;100 way of expressing a range, I've instead put range boundaries as separate conditions within an AND clause. It's no better or worse, but I find it easier to parse that way.

答案3

得分: 0

感谢反馈!很抱歉以错误的格式发布问题,下次会做得更好。
在 Excel 中对我有效的公式是:(我现在从手机上写这个,所以对于任何代码块错误和类似问题,敬请谅解)

=IF(A2>5, "红色", IF(AND(1<A2,A2<5,1<B2,B2<40), "黄色", IF(AND(1<A2,A2<5,40<B2,B2<60), "红色", IF(AND(1<A2,A2<5,60<B2,B2<100), "黄色", "绿色"))))
英文:

thanks for the feedback! And sorry for posting the question in a wrong «format», will do better next time.
The formula that worked for me in excel is: (i am writing this from my phone so sorry for any code block errors and such)

    =IF(A2&gt;5; &#171;Red&#187;; IF(AND(1&lt;A2;A2&lt;5;1&lt;B2;B2&lt;40); &#171;Yellow&#187;; IF(AND(1&lt;A2;A2&lt;5;40&lt;B2;B2&lt;60); &#171;Red&#187;; IF(AND(1&lt;A2;A2&lt;5;60&lt;B2;B2&lt;100); &#171;Yellow&#187;; &#171;Green&#187;))))

huangapple
  • 本文由 发表于 2023年7月10日 16:16:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76651915.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定