M
M
MikeFred52022-02-15 14:17:05
Google Apps Script
MikeFred5, 2022-02-15 14:17:05

How to change value depending on cell color?

Such question: it is necessary for me that at change of color in one cell, other cell is automatically filled. For example, if we change the color of cell A1 to green, then "yes" was written in cell B1, and if it is red, then "no"

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Ivanov, 2022-03-10
@MikeFred5

You can do this https://docs.google.com/spreadsheets/d/1hl1zEArivM...

/**
 *  @customfunction
 */
function COLORED(range) {
  const book = SpreadsheetApp.getActiveSpreadsheet();
  const formula = book.getActiveRange().getFormula();
  const [skip, addr] = formula.match(/\((.*)\)/) || [undefined, undefined];
  if(addr){
    const range = (/!/.test(addr) ? book : book.getActiveSheet()).getRange(addr);
    return range.getBackgrounds().map(row => row.map(cell => {
      let res = ''
      switch(cell){
        case '#4285f4': res = 'Да';
        break;
        case '#ea4335': res = 'Нет';
        break;
        default:
        break;
      }
      return res;
    }));
  }
  return '-';
}

622a3093717d5512699131.png
But unfortunately this doesn't react to the color change, only the value.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question