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) {
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");
}
else {
sheetToColor.getRange(cell).setBackground("#ffffff");
}
}
}