我需要从Excel公式返回一个空单元格,但Excel似乎将空字符串或空单元格引用与真正的空单元格区别对待。所以本质上我需要

=IF(some_condition,EMPTY(),some_value)

我试着去做一些事情

=IF(some_condition,"",some_value)

and

=IF(some_condition,,some_value)

假设B1是空单元格

=IF(some_condition,B1,some_value)

但这些似乎都不是真正的空单元格,我猜是因为它们是公式的结果。是否有办法填充一个细胞当且仅当满足某些条件,否则保持细胞真正空?

编辑:按照建议,我尝试返回NA(),但对于我的目的,这也不工作。有办法用VB来做这个吗?

编辑:我正在构建一个工作表,它从其他工作表中拉入数据,这些工作表被格式化为将数据导入数据库的应用程序的非常特定的需求。我没有权限更改此应用程序的实现,如果值为“”而不是实际为空,则会失败。


当前回答

也许这是作弊,但很有效!

我还需要一个表作为图形的源,我不希望任何空白或零单元格在图形上产生一个点。的确,您需要设置图形属性,选择数据,隐藏和空单元格以“显示空单元格为间隙”(单击单选按钮)。这是第一步。

然后,在单元格中,可能会以不希望绘制的结果结束,将公式放在带有NA()结果的IF语句中,如=IF($A8>TODAY(),NA(), *formula to be *)

当出现无效的单元格值时,这将给出没有点的所需图形。当然,这使得所有具有无效值的单元格都要读取#N/A,这很混乱。

To clean this up, select the cell that may contain the invalid value, then select conditional formatting - new rule. Select 'format only cells that contain' and under the rule description select 'errors' from the drop down box. Then under format select font - colour - white (or whatever your background colour happens to be). Click the various buttons to get out and you should see that cells with invalid data look blank (they actually contain #N/A but white text on a white background looks blank.) Then the linked graph also does not display the invalid value points.

其他回答

Excel没有办法做到这一点。

Excel单元格中的公式的结果必须是数字、文本、逻辑(布尔)或错误。没有公式单元格值类型为“空”或“空白”。

我所看到的一个实践是使用NA()和ISNA(),但这可能也可能不能真正解决你的问题,因为其他函数处理NA()的方式有很大的不同(SUM(NA())是#N/ a,而SUM(A1)如果A1为空则为0)。

在IF语句中使用COUNTBLANK(B1)>0代替ISBLANK(B1)。

与ISBLANK()不同,COUNTBLANK()将""视为空并返回1。

那么你必须使用VBA了。您将遍历范围内的单元格,测试条件,并删除匹配的内容。

喜欢的东西:

For Each cell in SomeRange
  If (cell.value = SomeTest) Then cell.ClearContents
Next

我用的是一个小黑客。 我使用T(1),它返回一个空单元格。 T是excel中的一个函数,如果是字符串返回参数,否则返回空单元格。所以,你能做的是:

=IF(condition,T(1),value)

也许这是作弊,但很有效!

我还需要一个表作为图形的源,我不希望任何空白或零单元格在图形上产生一个点。的确,您需要设置图形属性,选择数据,隐藏和空单元格以“显示空单元格为间隙”(单击单选按钮)。这是第一步。

然后,在单元格中,可能会以不希望绘制的结果结束,将公式放在带有NA()结果的IF语句中,如=IF($A8>TODAY(),NA(), *formula to be *)

当出现无效的单元格值时,这将给出没有点的所需图形。当然,这使得所有具有无效值的单元格都要读取#N/A,这很混乱。

To clean this up, select the cell that may contain the invalid value, then select conditional formatting - new rule. Select 'format only cells that contain' and under the rule description select 'errors' from the drop down box. Then under format select font - colour - white (or whatever your background colour happens to be). Click the various buttons to get out and you should see that cells with invalid data look blank (they actually contain #N/A but white text on a white background looks blank.) Then the linked graph also does not display the invalid value points.