Page 1 of 1

Formula to change cell background color

Posted: Sun Nov 14, 2010 12:18 am
by neil-uk
Hi guys,

Is it possible in Calc to create a formula etc to change the background colour of a Box?

So, if 'Blue' was written in A1, A1's background colour would change to Blue.

Thanks
Neil

Title Edited. A descriptive title for posts helps others who are searching for solutions and increases the chances of a reply (Hagar, Moderator).

Re: A would it work question

Posted: Sun Nov 14, 2010 12:34 am
by Cambirder
Yes, provided you don't need to set more than 3 conditions you can do it through conditional formating,

Format > Conditional formatting.

Re: A would it work question

Posted: Sun Nov 14, 2010 3:20 am
by neil-uk
Hi, Thanks for this.

I was hoping for a few more colours - such as Red, Blue, Green, Yellow, Orange, Purple, White, Brown and Grey.

Are there any other options?

Thanks
Neil

Re: Formula to change cell background color

Posted: Sun Nov 14, 2010 11:41 am
by gerard24
Hi,

If you have more than 3 colors, you can use the STYLE() function.

First, define style you need (Blue, Red, Green.....) with stylist (F11)
Second, use STYLE() in conditional formatting.

Example :
STYLE.ods
(8.31 KiB) Downloaded 3471 times
GĂ©rard

Re: Formula to change cell background color

Posted: Sun Nov 14, 2010 9:05 pm
by neil-uk
Hi Gerard,

Thanks for sending this example over.

But, as I changed the drop down boxes for different colours, the backgrounds didn't seem to change.

I can't seem to work out the coding, and the Help menu isn't much help.

Can you explain it in some more detail please?

Thanks
N

Re: Formula to change cell background color

Posted: Sun Nov 14, 2010 10:24 pm
by Zizi64
Cellstyles.png
You need to create different cellstyles with different background colors based on Default cell style.
You must to name those cellstyles as color names, When you select (or type in) a color name into a cell, the applied "Conditional format" option will "compute" the style name from the cell content, and will apply it on cell.

Re: Formula to change cell background color

Posted: Sun Nov 14, 2010 11:12 pm
by neil-uk
Hi Guys,

Thaks for this.

The only issue I have now is that I want to apply these to multiple cells around the Spreadsheet.

If I select them all is going to muck up whats in my other formulas.

Will doing STYLE() automatically make each cell I have edited see itself, or will I need to go through each one and so STYLE(A1), STYLE(B5) etc?

Re: Formula to change cell background color

Posted: Sun Nov 14, 2010 11:45 pm
by gerard24
You can select all the cells you want to apply conditional formatting and write the formula STYLE(Cell wich have focus).
Or format one cell and copy to others with the paintbrush.
Or copy/paste special > Formats

A+