0

I have the following script that copies a Google Spreadsheet to a new folder. I would like to modify it so that rather than copying the entire spreadsheet it only copies the second sheet of the spreadsheet to the new file. I have spent considerable time adding and modifying variables and can't seem to accomplish it.

//Archive the Sheet
   var sheet = SpreadsheetApp.getActiveSpreadsheet();
   var lastrow = sheet.getLastRow();
   var range = sheet.getRange('A1:N' + (lastrow) + '');
   var date = new Date();
   var formattedDate = Utilities.formatDate(date, "CST", "MM-dd-yy")
   sheet.setNamedRange('Archive', range);
   var TestRange = sheet.getRangeByName('Archive').getValues(); 
   Logger.log(TestRange); 
   var destFolder = DriveApp.getFolderById("0Byeq4rjTXxVzVzJyQWZxY2pyODA"); 
   DriveApp.getFileById(sheet.getId()).makeCopy(formattedDate, destFolder); 

Any suggestions?

  • If copying a single sheet is not possible, is there any way that I could delete out the sheets I don't want in the destination sheet after it is created? I would then need to activate the source sheet again so I could continue with some additional actions. – jnohl Oct 7 '16 at 13:44
  • 1
    Don't use comments to add additional information, instead edit your question. – Rubén Oct 9 '16 at 0:10
1

Use copyTo(spreadsheet) method. If you want that the new spreadsheet has only the copied sheet, delete the default sheet by using deleteSheet(sheet).

  • The spreadsheet that is being copied over to the destination has 5 sheets within it. So I would need to be able to delete out the other four sheets that are not applicable to the archive while staying within the original sheet to continue work. Is this possible? – jnohl Oct 10 '16 at 18:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.