0

I am trying to return a ui.alert message when a cell color is white but return true if green. I was able to get it to return the message when the cell color is white but when I change the cell color to green, it still returns the message. I have a feeling it is something simple but I have tried for hours trying to figure out the issue but no luck.

//Validating Cell Color #00ff40 (green)
   var cell = "B6"; // The cell.
   var colors = ["#00ff40", "#ffffff"]; // The two colors to validate.

   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var sheet = ss.getActiveSheet(); // or ss.getSheets()[0];
   var range = sheet.getRange(cell);
   var currentColor = range.getBackground();
   var color = colors.find(e => e != currentColor);
   
  if (currentColor=="#ffffff"){
      
      ui.alert("Color is not green.");
      shUserForm.getRange("B6").activate();
      
      return false;

  }

  return true;
0

1 Answer 1

0

This works for me:

function testie() {
  var cell = "B6";
  var colors = ["#00ff40", "#ffffff"];
  const ui = SpreadsheetApp.getUi();
  var ss = SpreadsheetApp.getActive();
  var sheet = ss.getActiveSheet();
  var range = sheet.getRange(cell);
  var currentColor = range.getBackground();
  if (currentColor == "#ffffff") {
    ui.alert("Color is not green.");
    shUserForm.getRange("B6").activate();
    return false;
  }
  return true;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.