title: How to target and iterate through just one specific column (by column name) in Google sheets / apps script?
body: <p>So I have an OnEdit function that detects when data is copy and pasted into the spreadsheet and then where ever a color value is found, that cells background colour becomes that color.</p>
  
  <p>However, currently it is iterating through every cell in the spreadsheet which is very slow when data is copied and pasted. I only want it to iterate through and detect copy and pasted changes within the "CategoryColor" column of my spreadsheet. </p>
  
  <p>This is what I have so far, any help would be greatly appreciated! Thanks!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function onEdit(e) {
    
      var firstRow = e.range.getLastRow() - e.range.getHeight() + 1;
      var firstColumn = e.range.getLastColumn() - e.range.getWidth() + 1;
      var values = e.range.getValues();
      for (var i = 0; i &lt; e.range.getHeight(); i++) {
          for (var j = 0; j &lt; e.range.getWidth(); j++) {
              try {
                  // changes background colour of cell
                  e.source.getActiveSheet().getRange(firstRow + i, firstColumn + j).setBackground(values[i][j]);
                 
              } catch (e) {
                Logger.log(e);
              }
          }
      }
    
    // sets data validation
    setDataValidation(createColorList());
    getColumnData(activeSpreadsheet);
    getFullColumn(columnIndex, startIndex);
  }</code></pre>
  </div>
  </div>
  </p>