Changing cell style depending on cell input

Is it possible to change cell typography dynamically - depending on what is typed into the cell?

Eg. I type “water” in a cell and it gets a blue “water” background Later I type “Fire” and the background changes to “Fire”

Yes, that’s no problem. Search the forum or help (F1) for conditional format.

I’m not so familiar with “conditional format” - And in the “Help” is not so well documented (yet)

The above example for my question is kept simple.
In reality, I have an array with a total of 20 values for styles

I can see that I can solve the task if I create all 20 conditions via the conditional format method.
Can’t I do it differently and get rid of the conditional format?

I already have the form (using functions such as index and style) which perfectly solves the task of changing the style to one of the desired styles:

type-in-the-cell-value” = Whatever I type into the current cell and which must remain but with a special typography
”style-code” is the returned value out of 20 possibilities from an index function

So to be clear: I’m basically only asking how I make the dynamic value: ”type-in-the-cell-value”

IMPOV, this can only be done by code.
A cell cannot contain a value or text and a formula. It can only hold eather a value or text or a formula.

Thanks - I had a feeling about it
Then I have to get started with the twenty conditions in conditional format ,-)

PS IMPOV = In My Point Of View?

IMPOV: yes! Find attached an example file, which attaches the style according to the word in a cell.
Attach_Cellstyle_by_Code.ods (48.7 KB)

I can see, It works as I requested, but it would be nice if I knew how to use it / recreate it for my project :wink:

Simply name the cellstyle as the word in a cell it has to be attached to.
Cellstyle “red” will be attached to a cell containing the word “red”. How to use the maco is described within the sampe file.

Yes, it’s this one that I don’t have full control over:

REM  *****  BASIC  *****

Sub attachcellstyle (Event)
 aStyles = thisComponent.Stylefamilies.CellStyles.ElementNames
 for i = 0 to uBound(aStyles)
    sStyle = aStyles(i)
    if Event.String = sStyle then
       Event.CellStyle = sStyle
  next i
end sub

I must find time to read a bit about macros in LO at some point


Sub attachcellstyle(event)
   on error resume next
   event.CellStyle = event.String
end sub

ps.: more explicit:

Sub attachcellstyle(event)
  styles = thisComponent.StyleFamilies.CellStyles
  if  styles.hasByName(event.String) then
    event.CellStyle = event.String
end sub