有Excel公式返回0,使结果为空 [英] Have Excel formulas that return 0, make the result blank

查看:1068
本文介绍了有Excel公式返回0,使结果为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个经常出现的Excel问题,我有一些公式,如 INDEX(array,row,column),当没有结果返回0,而不是返回空白。 >

将零结果更改为空白的最佳方法是什么?



以下是我迄今为止所尝试的方法:



1)使用除以零。如果INDEX返回0,则会导致错误,然后过滤掉。

  = IFERROR(1/1 / INDEX(A, B,C),)

CONS:使公式更加凌乱,隐藏可能需要的错误



2)使用自定义格式

  0; 0 ;; @ 

CONS:

1)不能同时申请日期格式

2)当检查空白单元格时仍然没有使用条件格式(仍然为零,仅显示)



3)使用 IF 语句

  = IF (1/1 / INDEX(A,B,C))",(1/1 / INDEX(A,B,C)),)

CONS:凌乱重复



有没有人有其他/更好的想法?

解决方案

您可以在Excel中的模块中创建自己的用户定义的功能,例如(从内存中,因此可能需要一些调试,和语法可能因Excel版本而异):

 公共函数ZeroToBlank(x As Integer)As String 
如果x = 0然后
ZeroToBlank =
Else
ZeroToBlank = CStr(x)
如果
结束函数
/ pre>

然后可以简单地将 = ZeroToBlank(Index(a,b,c))插入到单元格中。



有一个很好的教程,只是这个主题这里



基本步骤是:




  • 使用工具 - >在Excel中打开VB编辑器宏 - > Visual Basic编辑器

  • 使用 Insert - >创建一个新模块。模块

  • 在该模块中输入上述功能。

  • 在要调用该功能的单元格中,输入公式
          = ZeroToBlank(<< whatever>)
    其中<< whatever>> 是您希望使用空白的值(如果为零)。

  • 请注意,此函数返回一个字符串,所以如果你想要像一个数字一样看起来,你可能想要正确的细胞。



请注意可能会有微小的变化取决于你的Excel版本。我的Excel版本是2002,它确实很旧,但它仍然是我需要的一切。


A recurring Excel problem I have is formulas such as INDEX(array,row,column) that return 0 when there's no result, rather than returning blank.

What is the best way to change the zero result to blank?

Here are approaches that I have tried so far:

1) Using division by zero. If INDEX returns 0, I cause an error that I then filter out.

=IFERROR(1/1/INDEX(A,B,C),"")

CONS: Makes the formula more messy and hides errors you may want to see.

2) Using custom formatting

0;-0;;@

CONS:
1) can't simultaneously apply date format
2) It doesn't work with conditional formatting when it comes to checking for blank cells (there is still the value of zero, it's just not shown)

3) UsingIF statements

=IF((1/1/INDEX(A,B,C))<>"",(1/1/INDEX(A,B,C)),"")

CONS: Messy repetition

Does anyone have any other/better ideas?

解决方案

You can create your own user defined functions in a module within Excel such as (from memory, so may need some debugging, and the syntax may vary among Excel versions as well):

Public Function ZeroToBlank (x As Integer) As String
    If x = 0 then
        ZeroToBlank = ""
    Else
        ZeroToBlank = CStr(x)
    End If
End Function

You can then simply insert =ZeroToBlank (Index (a,b,c)) into your cell.

There's a nice tutorial on just this subject here.

The basic steps are:

  • Open the VB editor within Excel by using Tools -> Macro -> Visual Basic Editor.
  • Create a new module with Insert -> Module.
  • Enter the above function into that module.
  • In the cells where you want to call that function, enter the formula
         =ZeroToBlank (<<whatever>>)
    where <<whatever>> is the value you wish to use blank for if it's zero.
  • Note that this function returns a string so, if you want it to look like a number, you may want to right justify the cells.

Note that there may be minor variations depending on which version of Excel you have. My version of Excel is 2002 which admittedly is pretty old, but it still does everything I need of it.

这篇关于有Excel公式返回0,使结果为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆