compare data from two columns in google sheets - google-sheets

I want to format cells in column C based on the value for column B.
For instance:
B
.75
.75
.5
.25
When column C gets a value. I want the cell color to change to represent a < = or > value, like so:
C
.75 = green
.5 = yellow
.25 = red
.25 = green
How can I do this without putting in a formula specific to each cell? There could be any number of cells.

Start with one cell. Go to Format -> Conditional formatting. Do your three rules (if C1 greater than B1, fill green, etc.):
Select the cell you wish to edit.
Under Format -> Conditional formatting:
The Conditional Formatting Window will open. You can select the rule you would like and add a formula as shown.
After each one, there is a button at the bottom of the dialog for Add another rule. Make sure that you don't use fixed (=$B$1) references in your formulas, but relative ones (=B1). Once you have all three rules, click done. Test it to make sure it works like expected.
Now all you have to do is select the cell that has the conditional format (C1) and click the Format Painter tool. Then just highlight any cells that you want to follow the same rules. Because you have relative references, the conditional formatting will shift (i.e. C2 will reference B2 and D2 will D1 will reference C1).
Google does all the hard work :)
Does that make sense?

Related

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.

Copy conditional formatting to other rows in Google Spreadsheets

I have set the conditional formatting for one row, in the way I want it for approx 50 other rows.
Applying the conditional formatting to each rows take too much time. Is there a script that could do this automatically?
The conditional formatting for each row (first row is 21) is that: if the date (AB20) is the same as H21, then color AB21 yellow; if the date (AB20) is the same as F21, then color AB21 green.
Thanks!
Don't copy conditional formatting: apply it to a range instead (range is entered when a conditional formatting rule is created or when it's edited). Write the custom formula as it should work for the upper left corner of the range. It will be automatically adjusted for other cells based on relative references, even though this may not be obvious.
In your case, the range should be AB21:AB and the custom formulas are either
= AB20 = H21 and = AB20 = F21 if the goal is to compare F and H of the current row with AB of the previous row.
= AB$20 = H21 and = AB$20 = F21 if the goal is to compare F and H of the current row with AB of row 20.

Conditional Formatting with lots of data

Anyway, I have a table in Google Spreadsheets that has a set of rows which each contain a name (Column A) and two Yes or No values (Columns G and H).
I would like a way to conditionally format the rows. I have been trying to learn the formatting but I feel this is well out of my league. The way I would like it all to be formatted is only in Column A. If G says "Yes" and H is empty, then yellow. If G says "Yes" and H says "No", red. If G says "Yes" and H says "Yes", green.
If it helps, here is a chart:
G H
Y -- Yellow
Y N Red
Y Y Green
An explanation of how it all works would also be much appreciated but if you only have the solution on how to do it, I will gladly take that.
METHOD 1 - Conditional Formatting Only
The easiest way to do this, using Conditional Formatting is as follows:
Select "Format >> Conditional Formatting":
These IF statements will be used color the cells Yellow, Red, and Green, respectively.
=IF(AND(G2="Yes",H2=""),"True")
=IF(AND(G2="Yes",H2="NO"),"True")
=IF(AND(G2="Yes",H2="YES"),"True")
METHOD 2 - New Column, using f(x), and Conditional Formatting
The code used to generate the text "Yellow," "Red," and "Green" is as follows (broken up in 2 lines only for easier readability):
=IF(AND(B2="Yes",C2=""), "Yellow",IF(AND(B2="Yes",C2="No"), "Red",
IF(AND(B2="Yes",C2="Yes"), "Green")))
This is a nested IF statement that will examine your "Yes"/"No"/null column cells. This statement looks for the conditions you specified and returns either "Yellow," "Red," or "Green" in a separate column.
Since your IF statement will output either "Yellow," "Red," or "Green," all you'll have to do is set your Conditional Formatting to look for these words and color the cell accordingly.
A great resource to learn more is the Google spreadsheet function list.
I've got it for you. It can be made using the conditional formatting in Google Sheet.
A Screen Shot attached
Right click your cell A, apply conditional formatting
Just apply it across your range in column A1:A500 something
and choose the "Format cells if..." and choose custom formula
(Just click Add another rule after each one so you don't have to repeat the range)
=IF(AND(G60="Yes",H60=""),"True") //Change the color to Yellow
=IF(AND(G60="Yes",H60="No"),"True") // Change the color to red
=IF(AND(G60="Yes",H60="Yes"),"True") // Change the color to green
You will have 3 rules of conditional formating
replace G60 and H60 with the starting row number
Edit ------------------ Forgot to add the explanation
The formula
IF(AND(G60="Yes",H60=""),"True")
"IF" is to check IF something is this or not. I added the "AND" so that we could put in 2 condition, since we need both conditions to be satisfied. and therefore the formula above in written form would be
IF(IF) BOTH(AND) G60 and H60 is "Yes" and "Empty" respectively, then it is True. So it will become the color I chose.
There might be another way to write the codes but this works :)

Conditional formatting based on another cell's value

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.

Conditional formatting, entire row based

I've searched and read through answers related to conditional formatting, but I can't seem to get mine to work, so maybe I'm doing something wrong.
I have a worksheet for work. It contains a list of animals in our shelter. What I'm attempting to do is color the entire row green if they've been adopted (noted by an "X" in column "G"). I've had =$G$2="X" and =$G2="X", but neither work. It'll only color the one row that was active when I set the rule, and when I enter "X" in another row, it does nothing. What am I missing?
Use the "indirect" function on conditional formatting.
Select Conditional Formatting
Select New Rule
Select "Use a Formula to determine which cells to format"
Enter the Formula, =INDIRECT("g"&ROW())="X"
Enter the Format you want (text color, fill color, etc).
Select OK to save the new format
Open "Manage Rules" in Conditional Formatting
Select "This Worksheet" if you can't see your new rule.
In the "Applies to" box of your new rule, enter =$A$1:$Z$1500 (or however wide/long you want the conditional formatting to extend depending on your worksheet)
For every row in the G column that has an X, it will now turn to the format you specified. If there isn't an X in the column, the row won't be formatted.
You can repeat this to do multiple row formatting depending on a column value. Just change either the g column or x specific text in the formula and set different formats.
For example, if you add a new rule with the formula, =INDIRECT("h"&ROW())="CAR", then it will format every row that has CAR in the H Column as the format you specified.
=$G1="X"
would be the correct (and easiest) method. Just select the entire sheet first, as conditional formatting only works on selected cells. I just tried it and it works perfectly. You must start at G1 rather than G2 otherwise it will offset the conditional formatting by a row.
To set Conditional Formatting for an ENTIRE ROW based on a single cell you must ANCHOR that single cell's column address with a "$", otherwise Excel will only get the first column correct. Why?
Because Excel is setting your Conditional Format for the SECOND column of your row based on an OFFSET of columns. For the SECOND column, Excel has now moved one column to the RIGHT of your intended rule cell, examined THAT cell, and has correctly formatted column two based on a cell you never intended.
Simply anchor the COLUMN portion of your rule cell's address with "$", and you will be happy
For example:
You want any row of your table to highlight red if the last cell of that row does not equal 1.
Select the entire table (but not the headings)
"Home" > "Conditional Formatting" > "Manage Rules..." > "New Rule" >
"Use a formula to determine which cells to format"
Enter: "=$T3<>1" (no quotes... "T" is the rule cell's column, "3" is its row)
Set your formatting
Click Apply.
Make sure Excel has not inserted quotes into any part of your formula... if it did, Backspace/Delete them out (no arrow keys please).
Conditional Formatting should be set for the entire table.
You want to apply a custom formatting rule. The "Applies to" field should be your entire row (If you want to format row 5, put in =$5:$5. The custom formula should be =IF($B$5="X", TRUE, FALSE), shown in the example below.
Use RC addressing. So, if I want the background color of Col B to depend upon the value in Col C and apply that from Rows 2 though 20:
Steps:
Select R2C2 to R20C2
Click on Conditional Formatting
Select "Use a formula to determine what cells to format"
Type in the formula: =RC[1] > 25
Create the formatting you want (i.e. background color "yellow")
Applies to: Make sure it says: =R2C2:R20C2
** Note that the "magic" takes place in step 4 ... using RC addressing to look at the value one column to the right of the cell being formatted.
In this example, I am checking to see if the value of the cell one column to the right of the cell being formatting contains a value greater than 25 (note that you can put pretty much any formula here that returns a T/F value)
In my case I wanted to compare values in cells of column E with Cells in Column G
Highlight the selection of cells to be checked in column E.
Select Conditional Format: Highlight cell rules
Select one of the choices in my case it was greater than.
In the left hand field of pop up use =indirect("g"&row())
where g was the row I was comparing against.
Now the row you are formatting will highlight based on if it is greater than the selection in row G
This works for every cell in Column E compared to cell in Column G of the selection you made for column E.
If
G2 is greater than E2 it formats
G3 is greater than E3 it formats etc

Resources