title: Google Apps Script: spreadsheets: How do I get number of sheets, set last one as active duplicate and rename?
body: <p>I can't seem to get the syntax correct...</p>
  
  <p>I'm trying to get the total number of sheets in a spreadsheet and set the last one to the active sheet. I then want to duplicate the sheet, rename and delete rows 3 to the last row.</p>
  
  <p>This is some of the code I've been playing with:</p>
  
  <pre><code>    var logbook = SpreadsheetApp.openById("keycode here");
      var logbookSheets = logbook.getSheets();
      var numSheets = logbook.getNumSheets();
      logbook.setActiveSheet(logbookSheets[numSheets]).duplicateActiveSheet();
  </code></pre>