title: Get Sheet By Name
body: <p>I'm trying to get the following formula to work:</p>
  
  <pre><code>function setDataValid(range, sourceRange) {
    var rule = SpreadsheetApp.newDataValidation().requireValueInRange(sourceRange, true).build();
    range.setDataValidation(rule);
  }
  
  function onEdit() {
    var aCell = SpreadsheetApp.getActiveSheet().getActiveCell();
    var aColumn = aCell.getColumn();
  
    if (aColumn == 2 &amp;&amp; SpreadsheetApp.getActiveSheet().getName() == 'Local' ) {
      var range = SpreadsheetApp.getActiveSheet().getRange(aCell.getRow(), aColumn + 1);
      var sourceRange = SpreadsheetApp.getActiveSpreadsheet().getRangeByName(aCell.getValue());
      setDataValid(range, sourceRange)
    }
  }
  </code></pre>
  
  <p>When debugging onEdit() it shows that sourceRange in setDataValid(range, sourceRange) is null. As the range is in my sheet 'Local' I'm trying to change the getActiveSpreadsheet() to a get spreadsheet by name. Anyone who can help ?</p>