0

I have a template sheet that I would like to be able be able to copy with a unique name.

Needing a single function to execute these steps:

  1. The document containing TEMPLATE is opened
  2. Button is pressed that executes a script to increase the number in C1 of TEMPLATE sheet
  3. TEMPLATE is then copied and to a new sheet & renamed with text "C1 + B1 + A1"

I have the below reference scripts. I'm able to increase the number on it's own, and separately rename the sheet with the C1 Cell reference. But cannot get them to work together in the order needed and it's missing the reference to add 2 more cells to the sheet name.

If there is something I should be putting between them to make mulitple scripts work in one function, this would be insanely useful to know.

function increment(){

// define the cell to be incremented
var cell = SpreadsheetApp.getActiveSheet().getRange("B1");

// get and set the cell value
var cellValue = cell.getValue();
cell.setValue(cellValue + 1);  // this increments by 1 but could be any number
}

function NEWQUOTE(){
   var ss = SpreadsheetApp.getActiveSpreadsheet();
   var menuEntries = [];
   menuEntries.push({name: "Duplicate Sheet", functionName: "Duplicate"});
   ss.addMenu("Scripts", menuEntries)

  // The code below makes a duplicate of the active sheet
  var ss = SpreadsheetApp.getActiveSpreadsheet()
  SpreadsheetApp.getActiveSpreadsheet().duplicateActiveSheet();

  // The code below will rename the active sheet to data in cell B1
 var myValue = SpreadsheetApp.getActiveSheet( ).getRange("B1").getValue();
 var sheet = SpreadsheetApp.getActive().getSheetByName('TEMPLATE');
 SpreadsheetApp.getActiveSpreadsheet().renameActiveSheet(myValue);
 sheet.getRange('B1').clearContent();
}

Your Answer

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

Browse other questions tagged or ask your own question.