[Solved] If/else to change background color?

Discuss the spreadsheet application
Post Reply
fxSol
Posts: 7
Joined: Fri Dec 14, 2018 11:30 pm

[Solved] If/else to change background color?

Post by fxSol »

Ok I now basic of programming and I am used to if/else clauses.
Now I am playing around with numbers and added this formula -

Code: Select all

=IF(D2 > median($D3:$D7))
Which gives me the desired bolean output of TRUE, but what if TRUE set background to "green" else "red"?
Last edited by Hagar Delest on Sat Dec 15, 2018 10:39 pm, edited 1 time in total.
Reason: tagged solved
Ubuntu18.1 OpenOffice 4.1.6
User avatar
Lupp
Volunteer
Posts: 3756
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: If/else to change background color?

Post by Lupp »

Did you study my answer to your previous post?
Didn't it work?
What do you expect?
Please describe to the needed detail what you want to achieve. Otherwise contributors trying to help are in danger to waste their time.
On Windows 10: LibreOffice 25.8.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: If/else to change background color?

Post by Villeroy »

Code: Select all

=STYLE(IF(D2 > median($D3:$D7);"green_cell_style";"red_cell_style")
or use conditional formats which works with constant values as well.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
fxSol
Posts: 7
Joined: Fri Dec 14, 2018 11:30 pm

Re: If/else to change background color?

Post by fxSol »

Wunderbar! Would not have guests it in million jahren! Viele danke!
Its's a big and complex application and to be honest I have not used excel and there is a steep learning curve.
Thanks for helping us mortals out!

Did not know we had a style function , more info here for the mortals -
https://wiki.openoffice.org/wiki/Docume ... E_function
Ubuntu18.1 OpenOffice 4.1.6
User avatar
Lupp
Volunteer
Posts: 3756
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: If/else to change background color?

Post by Lupp »

Well, you can use the STYLE() function to assign a cell style to a cell containing a formula. You cannot use it to apply attributes to cells containing data.
Are you aware of the fact that the cell style assigned by STYLE() will persist changes and deletion of the formula? Removing the STYLE() part from the formula will not afflict the already applied cell style.
STYLE() works compltely different than ConditionalFormat.
On Windows 10: LibreOffice 25.8.4 and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
fxSol
Posts: 7
Joined: Fri Dec 14, 2018 11:30 pm

Re: If/else to change background color?

Post by fxSol »

Lupp wrote:Well, you can use the STYLE() function to assign a cell style to a cell containing a formula. You cannot use it to apply attributes to cells containing data.
Are you aware of the fact that the cell style assigned by STYLE() will persist changes and deletion of the formula? Removing the STYLE() part from the formula will not afflict the already applied cell style.
STYLE() works compltely different than ConditionalFormat.
You must understand that this all is still "greek" for me until I get my hands dirty and learn everything from inside out =)

I have a problem though, value always returns 0 with no cell formatting at all. If I remove the style function, everything works ok. Could it be that on this computer I use Libreoffice and not OpenOffice?
Maybe I need to add "style" called "red" and "green"??
Ubuntu18.1 OpenOffice 4.1.6
User avatar
Villeroy
Volunteer
Posts: 31363
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: If/else to change background color?

Post by Villeroy »

You must understand that this all is still "greek" for me until I get my hands dirty and learn everything from inside out =)
Start learning from outside in. Get a good book on spreadsheets. Any Excel book of the 90ies will do. For Calc I would recommend the documentation on the websites of OpenOffice or LibreOffice respectively. Take some time. This will be your first programming language. Learn systematically about data entry, sheet navigation, types of values, function arguments, relative and absolute addressing, cell styles. Conditional formatting combines more than one concept.
Then read this topic again and everything will be crystal clear.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply