[英]Excel formula returning false on certain cells
I have a nested IF statement in excel in several columns that is returning FALSE on certain cells. 我在Excel中的几列中都有一个嵌套的IF语句,该语句在某些单元格上返回FALSE。
=IF(DATEDIF(B2,C2,"y")<5,3.077,IF(AND(DATEDIF(B2,C2,"y")>5,DATEDIF(B2,C2,"y")<10),3.5385,IF(AND(DATEDIF(B2,C2,"y")>10,DATEDIF(B2,C2,"y")<15),3.846,IF(AND(DATEDIF(B2,C2,"y")>15,DATEDIF(B2,C2,"y")<20),4.308,IF(AND(DATEDIF(B2,C2,"y")>20),4.615)))))
These work: 这些工作:
B2 - 2/3/95, C2 - =Today() B2-2/3/95,C2-= Today()
B2 - 2/21/08, C2 - =Today() B2-2/21/08,C2-= Today()
B2 - 9/1/99, C2 - =Today() B2-9/1/99,C2-= Today()
These don't: 这些不:
B2 - 2/6/12, C2 - Today() B2-2/6/12,C2-今天()
B2 - 3/1/07, C2 - Today() B2-2007年3月1日,C2-今天()
B2 - 12/8/11, C2 - Today() B2-12/8/11,C2-今天()
B2 - 3/31/97, C2 - Today() B2-3/31/97,C2-今天()
Any help would be greatly appreciated. 任何帮助将不胜感激。
Your problem is that you have created a 'pocket' where the difference in years in neither less than 5 or greater than 5; 您的问题是您创建了一个“口袋”,其中年差不小于5或不大于5; in other words, 5. You could fix this by adding an equal sign to one of them; 换句话说,5.您可以通过向其中一个添加等号来解决此问题; eg <= 5 or >=5. 例如<= 5或> = 5。
However, you might also wish to use the logic of an IF statement and reduce your formula substantially. 但是,您可能还希望使用IF语句的逻辑并大幅减少公式。 Once you test for less than 5 you know that anything that continues in the FALSE processing portion of that IF is going to be 5 or greater. 一旦测试少于5个,您就会知道在IF的FALSE处理部分中继续进行的所有操作将等于或大于5。 You do not have to test for that. 您不必为此进行测试。
=IF(DATEDIF(B2,C2,"y")<5, 3.077,
IF(DATEDIF(B2,C2,"y")<10, 3.5385,
IF(DATEDIF(B2,C2,"y")<15, 3.846,
IF(DATEDIF(B2,C2,"y")<20, 4.308,
4.615))))
This can also be written as a LOOKUP function. 这也可以写为LOOKUP函数。
=LOOKUP(DATEDIF(B2,C2,"y"), {0,5,10,15,20}, {3.077,3.5385,3.846,4.308,4.615})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.