I need to format a cell if it is empty and another cell contains an specified value.
For example
IF(A = "Type 1" AND B = "")
THEN FORMAT
Try:
Conditional formatting on A1.
Apply to range:
A1:A
Custom formula is:
=and(A1="Type 1",B1="")
Related
I have 2 sheets A and B. I want sheet A to colour cells if the exact same cell in sheet B is not empty. For example if cell A1 in sheet B has a string, then cell A1 in sheet A will be coloured.
Let's say I want to do this to compare a large range, how should I go about doing this?
Example: https://docs.google.com/spreadsheets/d/1P3Ob_mclpXWmILfKwD4R6JN2wAYPUcNZlmtF9LxilV0/edit?usp=sharing
Cells A2:C2, D5 and K2 in sheet B are not empty. So the corresponding cells in sheet A will be coloured red.
You can use the following formula as a conditional formatting rule:
=NOT(ISBLANK(INDIRECT("B!"&address(row(),column()))))
(the formula in A!A2 is there to just show you what happens in sheet B)
Explanation:
Not familiar how this could be done with a custom conditional formatting formula so wait for other guys to help you out with that.
However, I can offer you a Google Apps Script solution.
The following script will check for the data range in sheet B and it will construct a color array. An element of this array will have the white hex color #ffffff" if the value in the values array is empty, or a red color #ff0000 if the value is not blank.
Then it will color sheet A based on this color array in one go. The script is relatively fast even for large ranges.
Solution / Workaround:
Don't forget to adjust "sheet A" and "sheet B" to the name of your sheets.
function colorCells(){
const ss = SpreadsheetApp.getActive();
const sheetToColor = ss.getSheetByName("sheet A");
const sheetToCheck = ss.getSheetByName("sheet B");
const bValues = sheetToCheck.getDataRange().getValues();
const aColors=bValues.map(r=>r.map(v=>v==''?"#ffffff":"#ff0000"));
sheetToColor.getRange(1,1,sheetToCheck.getLastRow(),sheetToCheck.getLastColumn()).
setBackgrounds(aColors);
}
How to use that:
Click on Tools => Scipt editor, copy, paste & save the aforementioned code and then execute it by clicking on the play button.
If you want this to work "automatically" then you can set up a time trigger to execute this function for you every n minutes.
Bonus code:
You can do the same operation but on a more user-interactive way. Again, copy, paste & save the following script to the script editor but this time don't execute it as it can work by itself.
The following script will change the color of a cell in sheet A upon user edits on the same cell in sheet B:
function onEdit(e) {
// adjust this to your needs:
const sheetToColorName = "sheet A";
const sheetToCheckName = "sheet B";
const rng = e.range;
const cell = rng.getA1Notation();
if (rng.getSheet().getName()==sheetToCheckName){
const sheetToColor = e.source.getSheetByName(sheetToColorName);
if(rng.getValue()!=''){
sheetToColor.getRange(cell).setBackground("#ff0000"); //red
}
else {
sheetToColor.getRange(cell).setBackground("#ffffff"); //white
}
}
}
I am trying to compare to cell in google sheet. Both the cell contains Value "Saturday".
Cell A1 = TEXT(WEEKDAY(N1),"dddd") value is "Saturday"
Cell A2 = =B2 value is "Saturday"
but when I compare both =IF(A1=A2,"TRUE","FALSE") Result is FALSE. I tried changing both cell to plain text but it did not work. Any solution?
How can I check in Google Sheets if each cell in a range e.g. B2:G2 contains a word e.g. holiday?
=ARRAYFORMULA(IF(IFERROR(REGEXEXTRACT(B2:G2, "holiday"))<>"", TRUE))
=ARRAYFORMULA(IF(SUM(IF(IFERROR(REGEXEXTRACT(B3:G3, "holiday"))<>"", 1))=6, TRUE))
I have a row A with 200 text entries.
A1 = "A1value"
A2 = "A2value"
A3 = "A3value"
...
I want to dynamicaly display in a single cell (text format) : ga=A1value,ga=A2value,ga=A3value, [...] ga=A200value etc...
use join function:
=JOIN(",ga=", A1:A3)
for some regions semicolon is used:
=JOIN(",ga="; A1:A3)
next step: add first "ga=" manually:
="ga="&JOIN(",ga=", A1:A3)
I am trying to get a Google spreadsheet to automatically highlight all rows in a spreadsheet where the value in a particular column is above 0. I have looked for a few solutions but haven't got it to work.
I have got various metrics in the columns, so say I want to highlight all rows, in which column "I" has a value of more than zero.
Can someone help me with this?
On the conditional formatting page choose "Custom formula is" from the list of options available and then in the text field type:
=$I:$I>0
Select your formatting options and then in the range field type the range. For example:
A2:Z100
Because only to be applied to a single column there is a simpler version (that I have complicated so that text is not highlighted):
Clear formatting, select ColumnI and Format, Conditional formatting..., Format cells if... Custom formula is and:
=and(isnumber(I1),I1>0)
with fill of choice and Done.
If to format not just the relevant cell but the entire row then change the Apply to Range (say to A1:Z1000) and add anchors ($s) as below:
=and(isnumber($I1),$I1>0)
The only solution I'm aware of would be to write a script.
Link: Google Apps Scripts
The following is not pretty, but it works:
function myFunction() {
var I_INDEX = 1;
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Highlight rows");
var dataRange = sheet.getDataRange();
var dataValues = dataRange.getValues();
for (var i=1; i<=dataRange.getNumRows(); i++) {
var row = sheet.getRange(i, 1, 1, 2);
if (dataValues[i-1][I_INDEX] > 0) {
row.setBackground("red");
}
}
}
See example, use "Tools" --> "Script Editor..." to view/run the script.