title: Google Apps Script custom function for sheets - range not found
body: <p>I have an issue that's likely due to my lacking understanding on how the getRange() function works.</p>
  
  <p>I wrote two small functions to use in a Google Sheet, but I can't get cell references to work properly as input. Here is the code:</p>
  
  <pre><code>function getCellRGB(input, color) {
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheets()[0];
  
    var cell = sheet.getRange(input);
    var hex = cell.getBackground();
    hex = hex.replace('#','');
  
    if (color == "r") return parseInt(hex.substring(0,2), 16);
    else if (color == "g") return parseInt(hex.substring(2,4), 16);
    else if (color == "b") return parseInt(hex.substring(4,6), 16);
    else return null;
  
  }
  </code></pre>
  
  <p>This only works if I input like this: </p>
  
  <pre><code>getCellRGB("A1", "r")
  </code></pre>
  
  <p>if I attempt to use a normal cell reference like they are used in other functions:</p>
  
  <pre><code>getCellRGB(A1, "r")
  </code></pre>
  
  <p>I get the error "Range not found (line 6)"</p>
  
  <p>The second function colors a cell from a R, G and B value in one cell each:</p>
  
  <pre><code>function setCellColorFromRGB(red,green,blue) {
  
    var ss = SpreadsheetApp.getActiveSpreadsheet();
    var sheet = ss.getSheets()[0];
  
    var r = sheet.getRange(red);
    var g = sheet.getRange(green);
    var b = sheet.getRange(blue);
  
    cell.setBackgroundRGB(r, g, b)
  
  }
  </code></pre>
  
  <p>I get the same error for this one, also line 6.</p>