英文:
Why doesn't a blank cell in excel evaluate to false?
问题
空单元格分别评估为以下内容:
英文:
A blank cell evaluates to each of the following:
When then does OR(A1,A1)
evaluate to an error, when A1
is equivalent to (or coerced to) both 0
and FALSE
? Is this a known inconsistency, or what's the reason for this behavior in Excel?
答案1
得分: 4
以下是翻译好的内容:
根据我在问题评论部分的回答,来回答问题。情况:OR(A1,A1)
返回 #VALUE!
可以通过查看 OR 文档来解释。以下是 OR
的语法:
OR(logical1, [logical2], ...)
它期望每个输入参数都有一个可以评估为 TRUE
或 FALSE
的逻辑条件。
在所引用文档的 备注 部分指出了空单元格的 OR
行为:
> 如果数组或引用参数包含文本或空单元格,那些值将被忽略。
在我们的情况下,A1
是一个空单元格,因此两个输入参数都被忽略。
在另一个备注项中,Microsoft 表示:
> 如果指定的范围不包含逻辑值,OR
将返回 #VALUE!
错误值。
这解释了为什么在这种情况下它返回 #VALUE!
,即没有输入参数是逻辑值。例如:OR(A1,A1,1=1)
返回 TRUE
,因为前两个输入参数被忽略,但最后一个评估为 TRUE
。由于空白单元格和文本的处理方式相同,因此对于空白的情况,OR(A1,A1)
的行为等同于 OR(""",""")
。
如果您希望针对此情况返回有效值,我们可以使用以下选项之一:
OR(ISBLANK(A1), ISBLANK(A1)) -> 用于检测空白
OR(A1="", A1="") -> 用于检测空值
请查看此链接:使用 IF 检查单元格是否为空。您还可以使用 LEN
函数,即 OR(LEN(A1)=0, LEN(A1)=0)
,正如 Exceljet 所建议的那样。请记住,测试空值与测试空白是不同的。如果 A1
具有值 =""
(或任何返回 ""
的公式),那么 ISBLANK(A1)
函数返回 FALSE
,但 A1=""
返回 TRUE
。
情况 OR(0,0)
不同,它返回 FALSE
,因为Excel将 0
视为 FALSE
,它进行了隐式转换,将 0
值强制转换为 FALSE
。
英文:
Just answering the question based on my response in the comment section of the question. The case: OR(A1,A1)
returns #VALUE!
can be explained looking at OR documentation. Here is the OR
syntax:
OR(logical1, [logical2], ...)
It expects a logical condition for each input argument that can evaluate to either TRUE
or FALSE
.
In the Remark section of the referred documentation indicates the OR
behavior for empty cells:
> If an array or reference argument contains text or empty cells, those values are ignored.
In our case A1
is an empty cell, therefore both input argument are ignored.
In another remark item, Microsoft states:
> If the specified range contains no logical values, OR
returns the #VALUE!
error value.
which explains why for this case it returns #VALUE!
, i.e. none of the input arguments are logical values. For example: OR(A1,A1,1=1)
returns TRUE
, because the first two input arguments are ignored, but the last one evaluates to TRUE
. Since blank cells and texts are treated the same way, the behavior of OR(A1,A1)
for the case of blanks is equivalent to OR("","")
.
If you want to return a valid value for this case, we can use one of the following options:
OR(ISBLANK(A1), ISBLANK(A1)) -> testing for blanks
OR(A1="", A1="") -> testing for nothing
Check this link: Using IF to check if a cell is blank. You can also use LEN
function, i.e. OR(LEN(A1)=0, LEN(A1)=0)
as it is suggested by Exceljet. Remember testing for nothing is different than testing for blanks. If A1
has the value =""
(or any formula that returns ""
) then ISBLANK(A1)
function returns FALSE
, but A1=""
returns TRUE
.
The case OR(0,0)
is different, it returns FALSE
because Excel treats 0
as FALSE
, it does an implicit conversion, coercing the 0
value to FALSE
.
答案2
得分: -1
你试图比较的两个单元格具有不同的数据类型。因此,没有OR(NUMERIC, BOOLEAN)函数,因此会出现错误/未定义的结果。
英文:
The 2 cells you're trying to compare are of different data types. There is no OR(NUMERIC, BOOLEAN) function therefore you get an error/undefined result.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论