Have Excel formulas that return 0, make the result blank

前端 未结 14 1931
别那么骄傲
别那么骄傲 2020-12-31 09:45

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

相关标签:
14条回答
  • 2020-12-31 10:14

    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.

    0 讨论(0)
  • 2020-12-31 10:14

    Perhaps the easiest way is to add the text formatting condition to the formula, with a ? modifier. Thus:

    (formula to grab values) becomes:

    text((formula to grab values),"?")

    Hope that helps.

    0 讨论(0)
提交回复
热议问题