Google Sheets: Conditionally Shade an Individual Set of Repeating Groups of Cells Based on Value - google-sheets

I have a Google Sheet I use to document my quotes for customers. I've copied and pasted it down the sheet several times. Within each quote is a list validated field where the options are "Won" or "Lost." When I select "Won," I want to turn that background color of JUST that quote green. However, I also only want to shade green the fields that I am not entering text into or accomplishing the calculations on (the data fields); I want to shade the background of the "form" and the "labels." (See screenshot where I did this by hand.)
I've attempted do this myself, but I'm having two issues.
I have to create separate conditional format rules for each quote/group of cells. This is tedious. I'd like, if possible, to create one rule that is able to adapt the conditional test of ="Won" to each group/quote separately.
I have to individually select each and every cell to be highlighted because if I just do A1:G33, all of the cells change color, even the ones in black and gray. I know this is expected, but is there a way around it?
I'm confused why applying the rule to the first group and copying and pasting it doesn't work. All of the quotes change green if the first quote shows "Won." This functionality works correctly with the built-in conditions that test the value of the cell itself. However, custom formulas to test the value of another cell don't "repeat" and operate individually it seems.
EDIT: Link to spreadsheet: https://docs.google.com/spreadsheets/d/1OH16NXLiRzY3-EdZaxmUl5Vp6cQNPzY-_-LV7VIDl8U/edit#gid=983650786

in your case perhaps best would be to color the first table exactly as you wish and then select it, copy it, select the first cell of the next table and:

Use Apps Script
This way you can have a lot of flexibility and its easier to manage.
You seem to already have an onEdit trigger, so you could integrate some more logic into that to test for statues. I can't implement everything you want but this should get you well on the way.
function onEdit(e){
// Getting the information on the edited cell
let editedCell = e.range;
let sheet = editedCell.getSheet()
// If the edited cell is in column 6, in "Quotes" and is value "Won"
if (editedCell.getColumn() == 6 && sheet.getName() == "Quotes" && editedCell.getValue() == "Won") {
// Get the row to know where to change the format
let statusRow = editedCell.getRow();
// Get the range of the whole form
let formRange = sheet.getRange(statusRow, 3, 17, 6)
// Set the background color
formRange.setBackground("green")
}
}
Hopefully you can see how you might extend this to include other ranges. You would need to base everything of the position of the edited cell. I have identified it by its column, the sheet that contains it, and its value. You can extend this to include checks on the value next to it for example. Then to change the color of each black box, you would need to define a range for each, relative to the edited cell.
References
setBackgroundColor
getRange

Related

How to (pre)format the (empty) cells of a Google Sheet so that the formatting sticks?

I want all cells of a Google sheet to be formatted identically (same font, same font size, same wrapping, same alignment). However, even if I select the whole sheet and set all formatting values, every time I enter a new value in an empty cell (sometimes copy-pasted from web pages, sometimes typed), the 'preset' formatting specs seem to have been lost and I must respecify them. Does someone know of a way to make the preformatting stick?
Copying and pasting the usual way brings with it the formatting of the source as best as Sheets can manage. Instead of using "Paste" or Ctrl-V, use "Paste Special" (Ctrl-Alt-V). A small clipboard icon will appear to the lower right of the on-screen paste area. Click it and choose "Paste values only."
This must be done even if you paste from one sheet within Google Sheets to another. If you just paste the regular way, it not only brings in the formatting of the source sheet, it breaks up any existing conditional formatting ranges you have in place.
Try using CTRL+SHIFT+V to paste. Doing so will only paste the copied value to the sheet without affecting the formatting.
Potential workaround:
With Apps Script you can run a simple onEdit() trigger to run every time an edit is made on the sheet. So you could use this to run a script that changes the format of cells every time an edit is made.
This would involve getting the whole data range and getting the rich text values of each cell, making a copy of the rich text value object and modifying it with the RichTextValueBuilder. This is turn involves copying and modifying the TextStyle with the TextStyleBuilder.
The wrapping and alignment are set on the whole range with setWrap(isWrapEnabled) and setHorizontalAlignment(alignment).
Example
function onEdit() {
// initialize main variables
let file = SpreadsheetApp.getActive();
let sheet = file.getSheetByName("Sheet1"); // change to your sheet name
let range = sheet.getDataRange();
// This sets the whole range wrap and alignment
range.setWrap(true);
range.setHorizontalAlignment("center")
// Get the rich text values in a 2D array
let richTextValues = range.getRichTextValues();
// Two map functions to return the modified 2D array.
let newRichTextValues = richTextValues.map(row => {
return row.map(cell => {
// Gets the text style from the richText value
let style = cell.getTextStyle()
// Copy the text style and set the bold, font and size
let styleCopy = style.copy()
.setBold(true)
.setFontFamily("Comfortaa")
.setFontSize(11)
.build();
// Set the new rich text value
let newRichTextValues = cell.copy()
.setTextStyle(styleCopy)
.build();
return newRichTextValue
})
})
// Set the whole range to the rich text value.
range.setRichTextValues(newRichTextValues)
}
This should work as-is by copying this into the script editor, trying to run it once from there to get the authorizations done, and then editing your sheet. Remember to add in your sheet name.
Demonstration
This is what it looks like in action:
In this example, I used
Text wrapping as on.
Center alignment
Bold text
"Comfortaa" font
11 font size
You should change these attributes to the ones that you want. There are other attributes available to customize too.
As you can see, it could get a bit tricky if you need to exclude certain ranges, but this is absolutely possible depending on your exact use case.
It should also be mentioned that this is quite an inefficient approach, as it gets the whole range and updates everything. Ideally you want to identify the exact changes and update those, but again, this depends on your exact use case. To get the range that was modified with an onEdit trigger you can use the Event object.
References
simple onEdit() trigger
RichTextValue
RichTextValueBuilder
TextStyle
TextStyleBuilder
setHorizontalAlignment(alignment)
setWrap(isWrapEnabled)
Event object

A way to refer to the "Current cell" for a dynamic Conditional Formatting in Google Spreadsheets

To be more specific, I want the Conditional Formatting to check the content of the cell that is currently being formatted and be dynamic as I copy-paste the Conditional Formatting into another cell, without having to manually fiddle with the formula again.
So what I'm doing is this (using an example):
I have a list of foods categorized by type (Fruits, vegetables, etc...) and every week the list changes, so its not possible to add "hard values" to formulas, it has to be a cell reference under the category.
Which means that under the category "fruits" for example, in week 1 i can have: banana, apple and peach but totally different fruits another week.
Anyways, I also want to create a calendar with the days in the week, where I put 4 drop-down menus which correspond to the 4 types of food. The drop down menus update as I update the initial list of avaiable foods.
Now down to the real issue.
I want that the cell used for the drop down menu to take an specific color when the content of that cell contains a food inside a given category.
For example, I select Apple, it checks for the apple and applies the apple color to the cell.
I acheived this with this
=COUNTIF(A4:A6, INDIRECT("RC","FALSE"))
I found someone online using the INDIRECT("RC","FALSE") value to "reference" the current cell but its not working for me...
A4:A6 is the range of fruits and it will give the red color to the apple because i defined it in Conditionnal formatting.
Now when I copy the conditional formatting is not working for the other apples and I want to make it work for others, just by checking if the current cell contains a value in a range of cells, without manually changing the current cell for every cell.
https://docs.google.com/spreadsheets/d/15trOcNzucTJDDwuseQTsvjhioIGN9W4NEjhztmMZ1so/edit#gid=0
This is my google spreadsheet, please help ! I'm not sure if I can understand better. This is for a much bigger project and really need the help.
Current cell for conditional formatting is left top most cell in Apply to range range.
In your case it is D11. So you should use following formula:
=COUNTIF($A$4:$A$6, D11)

How do I format a cell, only when it's not empty, based on the input of another cell?

I'm working on a spreadsheet in Google Sheets for multiple people, and indicate in a column who the person the information on that row pertains to. I want to format cells on that column, only when they're not empty, based on what person is selected in another cell.
I can create functions to format things based on another cell's entry, but I don't know how to compound that with a function for not being empty. Sorry if this is super basic, I just can't figure it out.
Yep. This is a super simple thing to do.
1) Highlight the column where the person's name appears.
2) From the main menu, select Format, Conditional formatting.
3) In the sidebar click add a new rule. what you want to do is create one rule for each name that appears (or could appear) in that column.
4) Under "Format cells if, select "Text is exactly"
5) Type the name in the cell where it says Value or Formula
6) Choose a background colour to suit.
7) Click Done.
8) Repeat steps 3 to 7 for each person; but change the background colour in each case.
Here's an example.

Can you set up conditional formatting based on colors of other cells?

I'm a projectionist at a movie theater, and we have a spreadsheet to track all of our content chronologically. Each show has its own row, complete with all of the details regarding time, theater number, format (digital DCP, Blu-ray, 35mm, etc).
We use this to verify at-a-glance where we're at on managing the content to make sure everything is set up to go. I have conditional formatting set up in every cell so that if it's a Yes or - (meaning not applicable to that show) it turns green, and if it's a No or ? (meaning we haven't gotten that information yet) it turns red.
What I want to know is if it's possible to have another column specifically for an overall "Yes" or "No", based automatically on the contents of the rest of the row (for example, column "D" will be green for yes and red for no). So if a show has all of its criteria met for the rest of the row (E* through Z*), manually filled out to turn green, that one cell (D*) will automatically follow suit. If something is missing from the rest of the row and contains even one red cell (anywhere in E* through Z*), that one cell (D*) will stay red as well.
I realize it probably needs a bit of scripting involved for this, which is not within my realm of experience, but I'm not even sure if it's possible. A lot of the spreadsheet is inputted manually, so one more column with a manual cell isn't the most inconvenient, but if we could set it up to be automatic, that would be incredible.
To branch off my comment above:
Additionally, have the cells by default set to red (using the fill option). If any of the cells are "NO", the condition won't be met, and it'll show as red:
Using OR:
=AND(OR(A1="YES",A1="-"),OR(B1="YES",B1="-"),OR(C1="YES",C1="-"))

Formatting doors table in rpe

I want to display a Doors table with a different style for the first row using RPE.
for example, make the first row have a diferent background color, or other border style.
is there any simple way to do that?
Thanks,
Boris.
My solution was to use a variable called "firstRow" which is Assigned to True in an empty Container before the table, then on the row of the table it is assigned to False.
Then in the background properties I have a script that looks something like:
if (firstRow == "True") {
"SpecialColour";
} else {
"NormalColour";
}
A variation of this script needs to be used for each different property that changes, for example if the first row was centered, with a blue background and bold text, this would need three duplicates of the script. Alternatively if you are exporting to Word you can set a table style in the stylesheet, although I am not quite sure how to explain this without going through it myself again.
Hope that helped!

Resources