title: Google Sheets: getting a sheet by its index
body: <p>I am trying to get a sheet using a calculated index. I am having a problem but am unsure whether it's a problem converting a float to an integer or if there is a syntax error. What am I getting wrong?</p>
  
  <pre><code>function copySheetValues()
  {
  
    var spread = SpreadsheetApp.getActiveSpreadsheet();
    var sourceSheet = SpreadsheetApp.getActiveSheet();
  
    //get the source sheet data
    var sourceDataRange = sourceSheet.getDataRange();
    var sourceSheetValues = sourceDataRange.getValues();
    var sourceRows = sourceDataRange.getNumRows();
    var sourceColumns = sourceDataRange.getNumColumns();
  
  
    // get the source sheet index and set the next sheet index
    var sourcesheetIndex = sourceSheet.getIndex();
    var destinationsheetIndex = Math.round(sourcesheetIndex + 1);
  
    // get the next sheet
    var destinationSheet = spread.getSheets()[destinationsheetIndex]
  
    //destination.insertSheet(sourcename, 0);
    destinationSheet.getDataRange().offset(0, 0, sourceRows, sourceColumns).setValues(sourceSheetValues);
  
  }
  </code></pre>