Excel: How do I Display Specific Text in a Cell if the Value is 0

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Peter Dam
    New Member
    • Aug 2011
    • 5

    #1

    Excel: How do I Display Specific Text in a Cell if the Value is 0

    I use in Excel the formula =NETWORKDAYS(A2 ;B2)for calculating the number of days between the dates in cells A2 and B2. The result is in Cell C2
    However, I would like to display a Predifined Text in C2 if the result is zero.

    I suppose The Predifined Text can be in the formula bar in a sort of If statement.
    If 0 ,OK will be displayed in cell C2)
    It does not matter what in the cell will be displayed if result is not zero.

    I assume the cell C2 format must then be Text or General
    Normally I use Number for C2.

    May be, I also can or need to use an other formula?? DateDiff or something like that?? I do not know all possibilities.

    Who can help me
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Sounds like you're looking for the IF() function

    Comment

    • Mariostg
      Contributor
      • Sep 2010
      • 332

      #3
      Code:
      =if(NETWORKDAYS(A2;B2)=0,"OK",NETWORKDAYS(A2;B2))
      Last edited by Mariostg; Jan 11 '12, 06:46 PM. Reason: Changed IIf to if function statement.

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32669

        #4
        This can be done as a simple Format property. Something like :
        Code:
        0;-0;"Some text"
        The format property can be found in the Properties window of cells, rows and/or columns, etc.

        PS. @Mario. There is no worksheet function IIF() in Excel. IF() has the same use as IIf() does in VBA though.
        Last edited by NeoPa; Jan 11 '12, 06:21 PM. Reason: Added PS

        Comment

        • Mariostg
          Contributor
          • Sep 2010
          • 332

          #5
          @NeoPa. I am doing to much VBA, I have to go back to spreadsheets. I would have never thought of your answer. Love it.

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32669

            #6
            Thanks Mario. I always appreciate the support of you guys who do so much to keep things going here :-)

            NB. It's important to understand that the underlying data doesn't change. It's still a zero. All that changes is what is displayed (IE. The .Text property as opposed to the .Value).
            Last edited by NeoPa; Jan 11 '12, 06:33 PM.

            Comment

            • Peter Dam
              New Member
              • Aug 2011
              • 5

              #7
              I have tried this, but I can not get it working.
              I noted that thereis an IF statement

              IF(logical_test[value_if_tue];[value_if_false])

              But I do not know how to use this for my problem

              Comment

              • brentg
                New Member
                • Jan 2012
                • 9

                #8
                see Mariostg reply and enter :
                Code:
                =IF(NETWORKDAYS(A2;B2)=0,"OK",NETWORKDAYS(A2;B2)
                in cell C2. It should work. Then just copy the formula down the column.
                Last edited by NeoPa; Jan 11 '12, 10:22 PM. Reason: Added mandatory [CODE] tags for you

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32669

                  #9
                  Originally posted by Peter Dam
                  Peter Dam:
                  I have tried this, but I can not get it working.
                  You've tried what? In the circumstances (the thread to date) this makes little sense.

                  NB. Please read all the replies. You could save wasting much of your time (and ours of course).
                  Last edited by NeoPa; Jan 11 '12, 10:24 PM.

                  Comment

                  Working...