I have a spreadsheet that looks like (but much larger):
Both the student names and the house assignments are pulled from other sheets.
I am looking for a google script that would conditionally format a student name based on the house they are assigned to. The house assignment will always be listed in the cell to the right of the name.
I realize this can be done with conditional formating (For instance: Custom formula =B3:B4="6-Blue"), but it becomes an arduous process because I have to go into each vertical range individually to make a change if the house name changes. With a google script, I could find and replace all instances of a house name.
Something like Eric Koleda's answer may work, but I am unsure how to reference the ranges and add multiple values to search for.
You can still do this with conditional formatting!
You can set up conditional formatting on a per column basis, you don't have to change the formatting, only the name of the color in your house column.
Conditional formatting formula: =ISNUMBER(FIND("Red", $C4))
Conditional formatting range: B4:C
This will try and find the text Red within all cells in Column C starting at C4. If Red is found in a cell, FIND() will return the index of Red, if it doe snot find Red is returns an error. You can check this with ISNUMBER(), which returns true or false if the value is a number or not.
This will color the adjacent columns on that row within the range. ie. A range of B4:C will color the cells in column C and B, a range of just B4:B will only cause the cells in column B to be colored.
You only need to setup one conditional formatting per color, per set of columns that you have. After that, just changing the colors under your houses will change the formatting.
Here is an example sheet I made for you: Example Google Sheet
Picture of Sheet with formatting:
Related
I want to use color scale while doing conditional formatting in a column, based on the color scale used on another column. For example, if in A Column I am having names of students and in B column I am having their scores. I have done condition formatting using color scale in B column like lowest will be red and highest will be white and other shades of red for the scores in between. I want the column with names to have the same formatting as the scores. Kindly help
This can be done by replicating the formulas for your conditional formatting in Column B to also be reflective in column A.
If for example you have the value of 25 in column B and what to give this a red text colour. You would create a conditional formating rule that has the following settings
Apply to Range - B:B
Format Rules - Text Contains - 25
Formatting style - red text
You can then apply this format to column A with the following settings for a conditional formatting rule in column A
Apply to Range - A2:A10 (extend to the range you need)
Format Rules - Custom Formula is - =$B2=25
Formatting style - red text
If you then enter 25 into column B it should also format column A. You would then need to replicate this for every conditional format rule that you have
I'm looking to change the color of the cell in column A for a row that matches 3 different values across the column. Using Google Sheets, I have tried conditional formatting but can't figure it out.
Example: if column C is today's date, and if column G is also today's date, and if column M has the text "test" in it, then the cell in row A gets pink.
Conditional formatting will work, but I can't figure out how to add multiple required pieces to look for. I tried recording macros too but I'm new at this.
You can add the following custom formula and apply the conditional formatting to column A
=AND($C1=TODAY(),$G1=TODAY(),$M1="test")
I created this test sheet to demonstrate:
https://docs.google.com/spreadsheets/d/1ZJXdINEzy4Gh-OOIpxpiEZSrVtaS-GnFqMbw0FKcxNE/edit?usp=sharing
Friends Actually I am having some data in which some employees names are there along with time, where I want if only names are appearing two times in a given range then it should highlight with any color. Below is the data for better understanding I have highlighted two duplicate names with red. Any help is highly appreciated.
Data
https://docs.google.com/spreadsheets/d/1z3qK65eW4fjCfZrsA_zEIh8HhueLk1Sgp32E1Cf-u3g/edit?usp=sharing
Add a conditional formatting rule with formula:
=COUNTIF($A$3:$G$7,"*"®EXEXTRACT(A3,"^.+ (.+)$"))>1
$A$3:$G$7 is the range of the timetable (dollar signs required), where A3 is the top left cell (NO dollar signs)
Is it possible to check a cell's conditional highlight colour and act accordingly?
I have a list of Names where some people belong to the "Yellow" team and some the "Pink" team. The Yellow team get more points allocated depending on their level (Cell B3).
Referring to the screenshots attached, I can't work out how to direct the lookup to the appropriate column of points per level in 'Sheet2' relative to the chosen Name. Conditional highlighting (see screenshot) sets the cell colour according to the Name input into cell B2.
Cell B6 contains the following formula:
=vlookup(B3,Sheet2!A1:E11,match(B2,Sheet2!A1:E1,0),)
The formula worked when the reference table had Column B named as "Bob" but that is not what I want.
I want the B6 formula to realize which colour team the B2 Name is and pick from the appropriate data set in 'Sheet2'.
Any help appreciated if it is at all possible to lookup against cell highlight conditions.
Thanks!
There's no direct way of doing it. You might want to use the getBackground() function in Google apps script, but I don't think it's worth using scripts for this case. That would mean making the thing more complicated and less maintainable.
The easiest way you can achieve it is by using a helper cell.
You'll need the two teams listed in two columns. I'll assume to make things simple to have the two ranges E2:E30 for yellow names and F2:F30 for pink names
Add Color in cell A4 and the following formula in B4:
=IF(ISERROR(MATCH(B2,E2:E30,0)),IF(ISERROR(MATCH(B2,F2:F30,0)),"No color","Pink"),"Yellow")
You could then use the result of cell B4 for the VLOOKUP in cell B6.
The added advantage is that you wouldn't need that many conditional formatting rules: you can simply compare the color in B4 and assign a conditional formatting rule accordingly in B2. It's way more maintainable and less error-prone.
Using Named Ranges for conditional formatting (no script, no helper cell)
Since Francesco's excellent proposition on using formulas instead of a script is your choice, you could also try the following.
Turn your team ranges to Named Ranges (by going to Data>>Named Ranges from the top menu) and name them e.g. yellow and PINK
Apply conditional formatting to your data validated cells (B3:E3) by using these two formulas (under Custom formula is found at the end of Conditional formatting rules):
=REGEXMATCH(B3,""&JOIN("|",FILTER(INDIRECT("yellow"),INDIRECT("yellow")<>""))&"")
and
=REGEXMATCH(B3,""&JOIN("|",FILTER(INDIRECT("PINK"),INDIRECT("PINK")<>""))&"")
(Make sure you adjust your ranges according to your data)
Advantages:
It is your original cells that get color coded.
Named Ranges can be placed anywhere, on any tab and can grow to your needs.
You do not need the extra helper cell.
Make a note:
We must use INDIRECT when using named ranges with conditional formatting for the function to work.
We must also surround the named range with double quotes "". So, to refer to the named range yellow we use INDIRECT("yellow).
I want to make a small script in google script editor for spreadsheet that sum's cell's according to other cell. Something like:
IF (A2:P2)==Q2{
SUM (A3:P3)}
I want to sum the cells that contains a certain character. Here a example of my question. How can I do it?
You don't need a script for this. You are just describing SUMIF which
Returns a conditional sum across a range.
Using a copy of your sheet I got your desired result with this formula
=sumif(B3:P3,"A",B4:P4)
Then you could use absolute cell references to make it easier to copy this down.
=sumif($B$3:$P$3,"A",B4:P4)
Question has changed
Since you have changed the source sheet you are asking a related but different question. Same as before though... you don't need a script for this. You can use COUNTIFS(). You have two counting criteria. Count if the cell contains a letter and count if the header row contains a number. We break this up into two conditional sets.
=COUNTIFs(B3:P3,Q2,B2:P2,1)
Q2 is the cell that contains "A" and the 1 is the header columns we are counting.
In order to move this down the row by simple drag and drop you still need to use absolute reference in the cells that are not moving. Q2 and the header row specifically.
=COUNTIFs(B3:P3,$Q$2,$B$2:$P$2,1)
To make the sum (row per row) of all the columns that have 'A' in the header, try in Q4:
=ArrayFormula(MMULT(N(IF(B3:P3="A", B4:P11,)) , transpose(N(B3:P3="A"))))
Change 'A' to 'B' etc.. for 'sum of all B'
If you want the result to auto-expand when new rows are added use the formula like this:
=ArrayFormula(IF(LEN(A4:A), MMULT(N(IF(B3:P3="A", B4:P,)) , transpose(N(B3:P3="A"))),))
EDIT: based on new info, I updated the formula to:
=ArrayFormula(MMULT((B2:P2=row(B3:B10)-2)*(B3:P10="A"), TRANSPOSE(COLUMN(B2:P2)^0)))
Example sheet
Of course the SUMIF() proposed by Matt will equally work (and is definitely a lot simpler). To drag the formula down, use the dollar signs to 'freeze' the header row, e.g: sumif($B$3:$P$3,"A",B4:P4)).