title: Question about If Else statments and changing a variable
body: <p>I've got a question about a google app script I'm working on. I am completely new to this. I would like to be able to have a script run on a button press and duplicate the current sheet. I would then like it to be renamed based on the name of the active sheet. When I return the value of newName with a browser.msgBox the value of newName is defined. However when I test the script the error reads &quot;Cannot read property 'setName' of null&quot;. Can someone tell me where I've gone wrong?</p>
  <pre><code>var name = ss.getSheetName();
  var newName = &quot;&quot;
  
  
  function newMonth() {
    const ss = SpreadsheetApp.getActiveSpreadsheet();
    const sheet = ss.getActiveSheet();
    
    ss.duplicateActiveSheet();  
  
    if (name == &quot;January&quot;) {
    newName = &quot;February&quot;;
  } else if (name == &quot;February&quot;) {
    newName = &quot;March&quot;;
  } else if (name == &quot;March&quot;) {
    newName = &quot;April&quot;;
  } else if (name == &quot;April&quot;) {
    newName = &quot;May&quot;;
  } else if (name == &quot;May&quot;) {
    newName = &quot;June&quot;;
  } else if (name == &quot;June&quot;) {
    newName = &quot;July&quot;;
  } else if (name == &quot;July&quot;) {
    newName = &quot;August&quot;;
  } else if (name == &quot;August&quot;) {
    newName = &quot;September&quot;;
  } else if (name == &quot;September&quot;) {
    newName = &quot;October&quot;;
  } else if (name == &quot;October&quot;) {
    newName = &quot;November&quot;;
  } else if (name == &quot;November&quot;) {
    newName = &quot;December&quot;;    
  } else {
    Browser.msgBox(&quot;Please Create New Sheet&quot;)
  }
  
  SpreadsheetApp.getActive().getSheetByName(&quot;Copy of ${name}&quot;).setName(newName);
  
  };```
  
  </code></pre>