Can I change cell content that is displayed based on value?

Can I change what Libre Calc displays in a cell based on its value? E.g.:

  • If cell = 1 then display ‘Included’
  • If cell = 2 then display ‘Excluded’
  • If cell = 3 then display ‘N/A’

Then I would like the colour of the cell to change too but I’m pretty sure I know how to do that part.

Kind wishes - Patrick

Welcome Patrick!
There are several simple ways to implement this display of cell values. The easiest way is a custom Number Format Codes. Based on this example, you can create a custom code format string like

[<2][MAGENTA]"Included";[<3][RED]"Excluded";[BLUE]"N/A"

1 Like

The solution explained by @JohnSUN is clever.
I would nonetheless dissuade from using it.

  • It’s not ‘expandable’ to ‘many cases’.
  • It’s not so easily “maintainable” if some condition would need to be changed.
  • Formatting should probably not completely hide the actual content of a cell.
  • And in general …

I would suggest to produce the strings you want to be displayed directly in the cells where they shall be shown by a reworked formula, or to use an additional column where your signalling strings are produced as formula results based on the numeric results you have already.
This is rather clear and easily reworkable when needed. If you want to not show the numeric results it’s very simple to toggle hide/show for the respective column then only used as a helper column.
Concerning the CF for colors (e.g.) you want to display you have the choice then whether you want to base it on the numbers or on the strings.

Yes, this method is not much more complicated - it can be implemented, for example, using CHOOSE() function

=CHOOSE(A2;"Included";"Excluded";"N/A")

(if A2 is address of your cell)
To avoid displaying Err:502 when the cell contains any other number or is empty, you can wrap the entire expression in the IFERROR() function

=IFERROR(CHOOSE(A2;"Included";"Excluded";"N/A");"Wrong Number " & A2)

Now create cell styles for all possible cases and apply Conditional Formatting, listing all possible cases and specifying the desired styles…
Now hide column A so that the original number 1 (2 or 3) does not interfere with the perception of the text.

Not much more complicated

1 Like