How to get colored font with formula

Hi, I have this formula: =IF((F34-D34)<0;"YES";"NO") how/ can I get the system to color code the yes and no? Can I have the “yes” be one color and the “no” another color??

You can apply conditional CellStyles by your formula with the function STYLE():

=IF((F34-D34)<0;"YES"&T(STYLE("MyYesStyle"));"NO"&T(STYLE("MyNoStyle")))

The MyYesStyle and MyNoStyle cell styles must exist when you apply this formula. Just adjust the Font Color in the two cell styles.

And you can use the Conditional Format feature too…

Please do not propagate the overly misused STYLE() function, thank you.

Which would be easier and can you tell me step by step please? If had several people give me wrong formulas now

Sorry??
It works for me.
https://wiki.documentfoundation.org/Documentation/Calc_Functions/STYLE

Please upload YOUR sample file here first.

We had give you three working tips. You must study the applied functions and features.
The function STYLE(): Documentation/Calc Functions/STYLE - The Document Foundation Wiki
The Conditional Format feature: Applying Conditional Formatting
.
.
Here is the three tips in one sample file:
Colorize result.ods (10.1 KB)

3 solutions:
t89746.ods (18.3 KB)

Thank you, I still don’t understand how you got the red and the green though.

Yes, it works, but it is a misuse, it is always recalculated along with the formula and applies a style. Using STYLE() is almost never necessary, given that conditional formatting exists and does things better and is intended for this use. Furthermore, STYLE() is not standardized and not supported by any other spreadsheet implementation. Whenever I see STYLE() used I cringe, see also Spreadsheet Functions

The STYLE function should not be used without compelling reason, its purpose is the use with asynchronous Add-In functions to visually notify about the availability of a result. In almost all other cases using conditional formatting instead is a better choice.

(just added to the wiki as well).

It exists and generally works, but it has a serious bug:
https://bugs.documentfoundation.org/show_bug.cgi?id=133027

And the original question was:
“How to get colored font with formula

Conditional formatting is possible only if you are familiar with the most fundamental concepts of spreadsheets well known since 30 years at least.

  • Number vs. Text
  • Value vs. Format
  • Absolute vs. relative referencing
1 Like

=IF((F34-D34)<0,"YES",NO") is my formula. I want the YES to be green and the NO to be red. If you would like I can send you a copy of my spreadsheet if that helps you understand my spreadsheet

Have you seen (have you downloaded) the sample files (my sample file and Villeroy’s sample file) above? Both contain working examples for the three suggested ways.

1 Like

I see villroeys i Don’t think I saw yours.

…And…? Are these solutions not appropriate for you?

=IF((F34-D34)<0;1;0)
[RED]“No”;[GREEN]“Yes”;[RED]“No”

I keep getting err507 with your formula

I think: only the

=IF((F34-D34)<0;1;0)

is the formula. The next row is the format code for the applied Cell Style.