Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional formatting in Google Sheets: Can I use custom function in the 'custom formula is:' field?

While applying conditional formatting in Google spreadsheet, I was wondering if it's possible to use a custom function that I created via script editor in the field 'custom formula is:'. Here is what I did:

  1. Went to 'script editor' and typed my fn as follows:

    function foo (param1, param2, param3) {
      if (condition to check) {
        ...some action;
        return true;
      } else {
        return false;
      }
    }
    

    and saved.

  2. In sheet, selected cells and opened 'conditional formatting' dialog

  3. Created new rule and in the field 'custom formula is:' typed the following

    =foo(param1, param2, param3)
    

Unfortunately, this didn't work.


Addition

Here is the sample sheet...

See the two tasks in there. My aim is to have the 'task title' automatically written inside of the yellow field (see the task in row 6 where I entered the value manually).

What I already tried was: - Assign to every cell in range H5:BB7 following formula: =if(H$4=D5; B5; "")
This checks if the start date equals the cell date and displays the task title. That does the trick, however the content of the cell with task title is clipped even if 'overflow' is on because the next cell is not empty.

like image 983
bash2day Avatar asked Feb 15 '16 20:02

bash2day


People also ask

Can I use an IF formula in conditional formatting Google Sheets?

One of the methods to achieve Conditional formatting based on a custom formula is using the IF statement. The IF function works on the IF/THEN/ELSE condition syntax.


1 Answers

Short answer

A custom function can't be used as a part of a custom formula in the Google Sheets' conditional formatting built-in user interface.

Explanation

In Google Sheets, a custom function is like spreadsheet built-in functions but written by the user using the Google Apps Script editor. They can't modify other objects, only return one or multiple values.

By the other hand, a custom function only is calculated when it's added to a cell or when at least one of it's parameters changes. They can't use non-deterministic functions as parameters like NOW(), TODAY(), RAND() and RANDBETWEEN().

Test

In order to test the statement in the short answer, I created a did the following:

  1. Create a simple custom function
function two() {
  return 2;
}
  1. Add the custom function as part of a custom formula in the conditional formatting side panel
=two()=2

Result: Nothing changed.

References

  • Custom Functions in Google Sheets
like image 140
Rubén Avatar answered Oct 26 '22 22:10

Rubén