返回值为1的引用单元格为空

编程入门 行业动态 更新时间:2024-10-23 13:38:46
本文介绍了返回值为1的引用单元格为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在Excel中,如果引用的单元格为空,我需要返回 1 的值

我可以

解决方案 / div>

您可以使用:

= IF(ISBLANK(A1),1,0)

但你应该小心你的意思是空单元格。我以前被抓到了。如果你想知道一个单元格是否真的空白, isblank ,如上所述,将会工作。不幸的是,您有时也需要知道它是否只包含有用的数据。

表达式:

= IF(ISBLANK(A1),TRUE,(TRIM(A1)=))

将为真正为空白的单元格返回true,否则只包含空格。

列 A 包含不同数量的空格,列 B 包含长度(所以你知道有多少空格)和列 C 包含上述表达式的结果:

< -A-& < -B-> < -C-> 0 TRUE 1 TRUE 2 TRUE 3 TRUE 4 TRUE 5 TRUE a 1 FALSE <-A - > < -B-> < -C->

如果单元格为空白或空格则返回1,否则返回0:

= IF(ISBLANK(A1),1,if(TRIM(A1)=,1,0))

会做的伎俩。

您正在检查的实际上是Excel函数的结果。许多Excel函数(如修剪)将返回一个空字符串,而不是一个空白单元格。

您可以使用新的工作表查看此操作。将单元格 A1 按原样设置,并将 A2 设置为 = trim(a1)。

然后将 B1 设置为 = isblank(a1)和 B2 到 isblank(a2)。你会看到前者是真实的,而后者是假的。

In Excel, I need to return a value of 1 if a referenced cell is empty

I can do it if the value is zero but how do I do it if it is empty?

解决方案

You can use:

=IF(ISBLANK(A1),1,0)

but you should be careful what you mean by empty cell. I've been caught out by this before. If you want to know if a cell is truly blank, isblank, as above, will work. Unfortunately, you sometimes also need to know if it just contains no useful data.

The expression:

=IF(ISBLANK(A1),TRUE,(TRIM(A1)=""))

will return true for cells that are either truly blank, or contain nothing but white space.

Here's the results when column A contains varying amounts of spaces, column B contains the length (so you know how many spaces) and column C contains the result of the above expression:

<-A-> <-B-> <-C-> 0 TRUE 1 TRUE 2 TRUE 3 TRUE 4 TRUE 5 TRUE a 1 FALSE <-A-> <-B-> <-C->

To return 1 if the cell is blank or white space and 0 otherwise:

=IF(ISBLANK(A1),1,if(TRIM(A1)="",1,0))

will do the trick.

This trick comes in handy when the cell that you're checking is actually the result of an Excel function. Many Excel functions (such as trim) will return an empty string rather than a blank cell.

You can see this in action with a new sheet. Leave cell A1 as-is and set A2 to =trim(a1).

Then set B1 to =isblank(a1) and B2 to isblank(a2). You'll see that the former is true while the latter is false.

更多推荐

返回值为1的引用单元格为空

本文发布于:2023-11-26 18:28:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1634691.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:值为   为空   单元格

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!