title: App script - Exception: You do not have permission to call setFontColor
body: <p>I'm trying to edit cells font based on other cells font on the same row but I can't edit their style using a custom function as I saw.</p>
  <p>My question is how to achieve this then ?</p>
  <p>Here is my code :</p>
  <pre><code>function colorCells(nameRange, valueRange) {
      var redHex = &quot;#ff0000&quot;;
      var orangeHex = &quot;#ff6d01&quot;;
  
      var activeRange = SpreadsheetApp.getActiveRange();
      var activeSheet = activeRange.getSheet();
  
      var range = activeSheet.getRange(valueRange);
      var rangeColor = range.getFontColors();
      console.log(rangeColor);
  
      var newColors = rangeColor.map(r =&gt; r.includes(redHex) ? redHex : r.includes(orangeHex) ? orangeHex : '#000000');
      console.log(newColors);
  
      var rangeToColor = activeSheet.getRange(nameRange)
      
      for (let i = 1; i &lt;= rangeToColor.getNumRows(); i++) {
        const cell = rangeToColor.getCell(i, 1);
        cell.setFontColor(newColors[i-1])
      }
  
      return &quot;&quot;;
  }
  </code></pre>
  <p><strong>EDIT :</strong></p>
  <p>To explain my objective, I have a column of strings and for each a row of data. And I want some of the data have different font color based on conditional formatting.</p>
  <p>So I want that if any data from a row is either red or orange the related column string change its color to the same one. Here is an example on an image.</p>
  <p>Before applying the function/script :</p>
  <p><a href="https://i.stack.imgur.com/r8xuJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r8xuJ.png" alt="enter image description here" /></a></p>
  <p>After :</p>
  <p><a href="https://i.stack.imgur.com/F2jGn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F2jGn.png" alt="enter image description here" /></a></p>