Create and Populate a Sheet from Template onEdit

Using an onEdit trigger to create a sheet from a template and fill in relevant information.
Important notes:
* Do not run the script manually. Like all onEdit() scripts, the ‘e’ parameter passes necessary information to the script and only exists when run automatically from an edit.
* Watch the ranges carefully.
* You can call the values from the data variable directly where needed rather than making individual variables.

Sheet (to copy – use File then “Make a copy” to get a full copy in your Drive):

function onEdit(e){
if (e.source.getActiveSheet().getName() != “Roster” || e.range.columnStart != 4) return;
const sh = SpreadsheetApp.getActive();
const template = sh.getSheetByName(“TEMPLATE”);

let data = e.range.offset(0,-3,1,4).getValues();
let fName = data[0][1];
let lName = data[0][0];
let sDate = data[0][2];
let position = data[0][3];

let newSheet = template.copyTo(sh).setName(fName + ” ” + lName);
newSheet.getRange(“A1″).setValue(fName + ” ” + lName);

Connect with me:
• Twitter @FarrisSpencer
• Google Product Expert

Leave a Reply

Your email address will not be published. Required fields are marked *