You are currently offline, waiting for your internet to reconnect

Changing Text of Formula Result Based on Return Value

This article was previously published under Q133049
Retired KB Content Disclaimer
This article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
SUMMARY
In Microsoft Excel, a function cannot automatically format text based onthe type of value it returns. However, you can create a custom numberformat that will return different colored text, based on whether yourfunction returns a positive, negative, or zero value.
MORE INFORMATION
In Microsoft Excel, number formats are based on the following:
   [color1]positive# format;[color2]negative# format;[color3]zero# format				
To have a function return up to three different types of text value, eachwith a different color, have the function return either a positive number,a negative number, or a zero value, and format the custom number formatsuch that it displays text based on those values. For example, thefollowing custom number format
   [red]"after";[blue]"before";[green]"same"				
will display the word "after" in red if the function returns a positivenumber, the word "before" in blue if the function returns a negative value,and the word "same" in green if the function returns 0.

Example

  1. Type the following formula into a worksheet:
    A1: =IF(A5>DATEVALUE("2/28/95"),1,IF(A5<DATEVALUE("2/28/95"),-1,0))
  2. Apply the following custom number format to the cell:
          [red]"after";[blue]"before";[green]"same"						
  3. In cell A5, type 6/1/95.

    Cell A1 will display the word "after" and the word will be formatted in red.
  4. In cell A5, type 2/28/95.

    Cell A1 will display the word "same" and the word will be formatted in green.
REFERENCES
"User's Guide," version 5.0, Chapter 12, "Formatting a Worksheet"

For more information about Custom Number Formats, choose the Searchbutton in Help and type:
number formats, creating custom
XL
Properties

Article ID: 133049 - Last Review: 08/19/2003 12:41:18 - Revision: 1.1

Microsoft Excel 95a, Microsoft Excel 5.0c, Microsoft Excel 5.0 Standard Edition, Microsoft Excel 5.0a for Macintosh

  • kbinfo KB133049
Feedback