1
votes

I was wondering is someone can help me figure out how to do the following:

  1. I have a custom function that returns a number and under a specific condition, let say number equals 1, I want the function to return the number and color the cell background as well.
  2. I have to check the condition within the function and not do a conditional formatting from the outside.

any suggestions?

1

1 Answers

-1
votes

You should take a look at Range classe, on setBackground(string) or on setBackgroundRGB(int, int, int) method, which give you the ability to color your range, as you wish.

Edit: Here is a workaround for using setBackground method in your case:

function onEdit(e) {

  var result = e.range.getValue();

  // Test your condition to change the color
  if(result > 3){

    var cell = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet().getActiveCell();
    cell.setBackground("red");

  }
}

The function will put a red background for all modified value who will be more than 3.