Conditional formatting based on another cell's value - google-sheets

I'm using Google Sheets for a daily dashboard. What I need is to change the background color of cell B5 based on the value of another cell - C5. If C5 is greater than 80% then the background color is green but if it's below, it will be amber/red.
Is this available with a Google Sheets function or do I need to insert a script?

Note: when it says "B5" in the explanation below, it actually means "B{current_row}", so for C5 it's B5, for C6 it's B6 and so on. Unless you specify $B$5 - then you refer to one specific cell.
This is supported in Google Sheets as of 2015:
https://support.google.com/drive/answer/78413#formulas
In your case, you will need to set conditional formatting on B5.
Use the "Custom formula is" option and set it to =B5>0.8*C5.
set the "Range" option to B5.
set the desired color
You can repeat this process to add more colors for the background or text or a color scale.
Even better, make a single rule apply to all rows by using ranges in "Range". Example assuming the first row is a header:
On B2 conditional formatting, set the "Custom formula is" to =B2>0.8*C2.
set the "Range" option to B2:B.
set the desired color
Will be like the previous example but works on all rows, not just row 5.
Ranges can also be used in the "Custom formula is" so you can color an entire row based on their column values.

One more example:
If you have Column from A to D, and need to highlight the whole line (e.g. from A to D) if B is "Complete", then you can do it following:
"Custom formula is": =$B:$B="Completed"
Background Color: red
Range: A:D
Of course, you can change Range to A:T if you have more columns.
If B contains "Complete", use search as following:
"Custom formula is": =search("Completed",$B:$B)
Background Color: red
Range: A:D

I've used an interesting conditional formatting in a recent file of mine and thought it would be useful to others too.
So this answer is meant for completeness to the previous ones.
It should demonstrate what this amazing feature is capable of, and especially how the $ thing works.
Example table
The color from D to G depend on the values in columns A, B and C. But the formula needs to check values that are fixed horizontally (user, start, end), and values that are fixed vertically (dates in row 1). That's where the dollar sign gets useful.
Solution
There are 2 users in the table, each with a defined color, respectively foo (blue) and bar (yellow).
We have to use the following conditional formatting rules, and apply both of them on the same range (D2:G3):
=AND($A2="foo", D$1>=$B2, D$1<=$C2)
=AND($A2="bar", D$1>=$B2, D$1<=$C2)
In English, the condition means:
User is name, and date of current cell is after start and before end
Notice how the only thing that changes between the 2 formulas, is the name of the user. This makes it really easy to reuse with many other users!
Explanations
Important: Variable rows and columns are relative to the start of the range. But fixed values are not affected.
It is easy to get confused with relative positions. In this example, if we had used the range D1:G3 instead of D2:G3, the color formatting would be shifted 1 row up.
To avoid that, remember that the value for variable rows and columns should correspond to the start of the containing range.
In this example, the range that contains colors is D2:G3, so the start is D2.
User, start, and end vary with rows
-> Fixed columns A B C, variable rows starting at 2: $A2, $B2, $C2
Dates vary with columns
-> Variable columns starting at D, fixed row 1: D$1

Basically all you need to do is add $ as prefix at column letter and row number. Please see image below

change the background color of cell B5 based on the value of another cell - C5. If C5 is greater than 80% then the background color is green but if it's below, it will be amber/red.
There is no mention that B5 contains any value so assuming 80% is .8 formatted as percentage without decimals and blank counts as "below":
Select B5, colour "amber/red" with standard fill then Format - Conditional formatting..., Custom formula is and:
=C5>0.8
with green fill and Done.

I'm disappointed at how long it took to work this out.
I want to see which values in my range are outside standard deviation.
Add the standard deviation calc to a cell somewhere =STDEV(L3:L32)*2
Select the range to be highlighted, right click, conditional formatting
Pick Format Cells if Greater than
In the Value or Formula box type =$L$32 (whatever cell your stdev is in)
I couldn't work out how to put the STDEv inline. I tried many things with unexpected results.

I just want to explain it in a another way. In "custom formula" conditional formatting you have two important fields:
Custom formula
Apply to
Let's say, you have a simple sheet with test percentages of students, where you want to color Student Ids(Column B) where their score(Column C) > 80%:
Row
B(Student ID)
C(Score)
1
48189
98%
2
9823
6%
3
17570
40%
4
60968
23%
5
69936
7%
6
8276
59%
7
15682
96%
8
95977
31%
To design a custom formula, you only need to design a formula for the top left of the range, you want to color. In this case, that would be B1.
The formula should return
TRUE, if it should be colored and
FALSE, if it shouldn't be colored
For B1, the formula would then be:
=C1>80%
Now imagine that you put that formula in B1(Or just use a another range to test it). It would be like:
Row
B
C
1
TRUE
2
3
4
5
6
7
8
Now imagine dragging the formula(or autofill) up to B8 from B1. This is how it would look like
Row
B
C
1
TRUE
2
FALSE
3
FALSE
4
FALSE
5
FALSE
6
FALSE
7
TRUE
8
FALSE
This translates directly to color B1 and B7. Now the interesting thing is All of this is autocalculated using the given formula for B1 and the Apply to range. If you fill:
Custom formula: =C1>80% and
Apply to: B1:B8
you're saying
Fill the custom formula =C1>80%
in the top left cell of the provided range B1:B8,i.e., B1 and
drag/autofill the formula to the whole range B1:B8 and
Color the cells, where the formula outputs TRUE
If you want to color both student IDs and score, you would use
Custom formula:
=$C1>80%
Apply to:
B1:C8
The $ in the $C1 says not to change C, when autofilling the range. In the imaginary table(I suggest you to output the table somewhere). This would look like:
Row
B
C
1
TRUE
TRUE
2
FALSE
FALSE
3
FALSE
FALSE
4
FALSE
FALSE
5
FALSE
FALSE
6
FALSE
FALSE
7
TRUE
TRUE
8
FALSE
FALSE
In this way, you can color any cell anywhere based on any other cell.

Related

Conditional formatting if cells in row are less than header

I am trying to find a way to have a cell in column A turn yellow if any cell in the adjacent row is less than the value of its corresponding header. Please see my example sheet.
I'm trying to use this formula for my conditional formatting: =COUNTIF(B5:5,"<"&B$4)>=1 but I believe it's stuck on using Cell B4 as the header value for the entire range (instead of C4 for column C, D4 for column D, etc).
Any ideas on what I'm missing here?
For the red option, as you suggested, you should use:
=COUNTIF($B5:$H5,"")
But you may keep it that option above, so it is red even if there's an orange
Then, for yellow you can use:
=COUNTIF(BYCOL($B5:$H5,LAMBDA(each,each<OFFSET(each,4-ROW(each),0))),TRUE)
It checks in each column if the value is smaller than in row 4, and counts the amount of TRUE values
And green should be by default, I understand. Is it useful?

Google Sheets Conditional Format for Multiple Columns

I am using google sheets. For column E, under the header “Received” I have formatted it so that when you type in "no" the color of that cell turns red. But when you type in “yes" then the color of the cell will change to green.
How do I get column F (column to the right of Column E, under the header “Total”) to automatically display the number "20" AND also the make it’s cell
turn to green whenever the cell next to it, in column E says "yes"? And if I type in “no” in Column E id like the cell next to it in Column F to say “0” and the background color change to red.
Please help!
I asked ChatGPT it said to use the formula =IF(E2=“yes”,”20”, “”) however this didn’t work. It only changed column F background color to green but it didn’t change the cell to say “20”
These are two separate things. One is the formula inside the cell that determines the value of 20 or 0
=IF(E2="","",IF(E2=“yes”,20,0))
Or you can set it as an array formula in F2 to expand to lower rows. Put this in F2:
=ArrayFormula(IF(E2:E="","",IF(E2:E=“yes”,20,0)))
Other thing is the conditional formatting rules that set the colours. Select F2 column and choose conditional formatting. Look for custom formula and you can use:
=E2="yes"
=E2="no"
For green and red respectively. Try these things and let me know
I was able to to get it right using the formula =IF(E2="yes", "20.00", "0.00").
That did the trick, and to change the colors I did conditional format and set it to Text contains: 20and changed the color to green. I added another rule except this time I put Text contains: 0.00 and changed the color to green.

Having issues with Conditional formatting in Google Sheets

I am working on building a weight loss calculator. I am having problems using conditional formatting in my spread sheet. I am trying to have it green if less than c2, and red if greater than c2 . c2 is performed via a v look up function. I have also tried custom function to no avail. Ideally I would like to break this down as a percentage of c2 and have yellow as well but 1 step at a time. I have tried converting to a value and an int and still it's not working correctly.
Thank you in advance!
Please try the following
Select Custom formula is
Put =F15<C$2
Repeat once more with =F15>C$2
To avoid formatting empty cells use =AND(G14<F$3,G14<>"")
To get the Desired result you should use 2 conditional formatting rules with 2 different formulas, for the same range F11:F
Formula 1 to Highlight the range F11:F the "Calories" column with Green
=ArrayFormula(IF(F11:F="",,F11:F<$C$2))
Formula 2 to Highlight the range F11:F the "Calories" column with Red
=ArrayFormula(IF(F11:F="",,F11:F>$C$2))
Since you didn't provide the sheet i did recreate it from scratch.
Explanation
IF Range F11:F is Empty "" Do nothing ,, if isn't Empty check if F11:F < $C$2 in case of green formula 1 and check F11:F > $C$2 in case of red formula 2 if TRUE Highlight green / red if FALSE do nothing.
ArrayFormula allow the usage of non-array functions with arrays and the ability to show values returned by an array formula over many rows and/or columns.

Conditional Formatting Row based on

I like to use Google Sheets to keep my list of stories that I'm working on organized
like in this photo here:
Each row is highlighted a certain color depending on the value of the cell in "B" Column. "Published" is green, "WIP" is orange, where for range A2:B2, =B2="Published"
But at the moment I have to create the conditional formatting formula (CF) for each row one by one. I have to make the CF for Row 2, then copy the CF to Row 3 and edit the formula to replace every B2 with a B3 so it works independently on the next row.
This seems far too tedious to do practically so I was wondering if there was a formula that would allow each row to be formatted individually with one formula? Something where the formula knows to look at B2 in Row 2 to apply the formatting, B3 in Row 3, and so on.
The current formula I'm using is [=B3="Published"] to change the formatting style to a green highlight. But if I do this on all of my cells, it will change all of rows based on the value of B2. Even though in B3 it might be "WIP" instead, which defeats the purpose of highlight. I was hoping it would function like [if: =BX="Published"/ then: apply conditional formatting to Row X]
I'm really sorry about the poor phrasing of this question, I have basically zero knowledge on Google Sheets and don't know how to phrase the question for Google or any other search engine
set your range to A2:F and use this set of formulae:
orange
=$B2="WIP"
blue
=$B2="Outline"
green
=$B2="Published"

Format one row as soon as cumulative sum reaches a particular number

I have a Google sheet that shows the number of KM a vehicle ran every day. Column E is the total distance. I want to change row background to red as soon as the value in E crosses 1000. And it should apply only to that one immediate row.
How to do it?
Select A5 to wherever suits, and apply a Conditional formatting formula rule of:
=countif($E$5:$E5,">1000")=1
You can do this directly with a formula from the Conditional Formatting option.
In my example I am shading the row in the area A1:B3 based on the values in C
Use the format cells if ... custom formula is option and put the conditions you want you range to change in there.
E.g. I am formatting my range to change to green when =$C1>=1000
Notice I don't need to change C1 to include all the rows, as it will evaluation on every for separately.

Resources