I am trying to create a Google Apps Script that will allow me to quickly determine if further action is needed by changing color of a cell. Currently I am performing an auditing process where I look at 5% of the product for errors. If too many errors are found, I need to look at 100% of the product.
I have been trying to create a script that upon meeting the error threshold will change the color of a cell and the following criteria is what needs to be met. I would use conditional formatting but opt for a script so that the escalation method is less apparent and so future expansion can manipulate formatting of text if needed.
- If a1 is less than or equal to 50 and b1 is less then four color cell c1 green
- If a1 is less than or equal to 50 and b1 is greater then four color cell c1 red
- If a1 is more than or equal to 50 and b1 is less than 4% of a1 then color cell c1 green
- If a1 is more than or equal to 50 and b1 is greater than 4% of a1 then color cell c1 red
Any and all help is greatly appreciated!
function onEdit(e) {
var ss = e.source.getActiveSheet();
var r = e.source.getActiveRange();
if (r.getRow() != 1 && ss.getName() == "Entry Form") {
Error_Count = ss.getRange(r.getRow(),3).getValue();
rowRange = ss.getRange(r.getRow(),1,1,3);
if (Error_Count < 3.8) {
rowRange.setBackgroundColor("#FF0000"); }
else if (Error_Count == 'N/A') {
rowRange.setBackgroundColor("#ffffff"); }
else if (Error_Count > 3.9) {
rowRange.setBackgroundColor("#ffffff");
}