Forgive me if my wording is off, I'm new to Scripts, but someone made me a script to run onEdit/Triggers for a sheet I have. I also have an onEdit script for a date/timestamp. I had them all working briefly yesterday, but then the new onEdit trigger scripts started failing; stating I had too many scripts. The ranges that are being imported upon the triggers have formulas and conditional formatting. The cell that's triggering the events for the Stage 1, Stage 2, Stage 3, and PIT codes is a data validation cell. The sheet link and codes are at the bottom of this post.
So what I'm wondering is:
- How to combine four(4) scripts into one(1) script, and
- If it's possible to add coding to the script to delete the range cells it imports before it places the new triggered cells. Because each range it imports has conditional formatting that lingers after the new range is triggered.
Sheet link: https://docs.google.com/spreadsheets/d/1KYSiVggIm7KIKxpJMnUhldrzsIaETCqyjOWJ1a9k1cI/edit?usp=sharing
Date/Timestamp Code:
function onEdit(e) {
const sheetNameFellowshipTracking = 'Fellowship Tracking';
const dateCol = 43;
// Get edited sheet.
const range = e.range;
const sheet = range.getSheet();
if (sheet.getName() === sheetNameFellowshipTracking)
{
// Get edited row.
const row = range.getRow();
if (row >= 4 && row <= 28)
{
// Get current time.
const time = Utilities.formatDate(new Date(), "GMT-05:00", "MM/dd, HH:mm");
// Set edited datetime.
const dateModifiedRange = sheet.getRange(row, dateCol);
dateModifiedRange.setValue(time);
}
}
}
Stage 1 Code:
function onMyEdit(e) {
var sh=e.range.getSheet();
if(sh.getName()!='Fellowship Tracking')return;
if(e.range.columnStart==7 && e.range.rowStart==31 && e.value=='Stage 1') {
var srcrg=e.source.getSheetByName('ALL Stages+Pit').getRange('B3:G21');
var desrg=sh.getRange('C33');
srcrg.copyTo(desrg);
}
}
function createOnMyEditTrigger() {
var ss=SpreadsheetApp.getActive();
ScriptApp.newTrigger('onMyEdit').forSpreadsheet(ss.getId()).onEdit().create();
}
Stage 2 Code:
function onMyEdit(e) {
var sh=e.range.getSheet();
if(sh.getName()!='Fellowship Tracking')return;
if(e.range.columnStart==7 && e.range.rowStart==31 && e.value=='Stage 2') {
var srcrg=e.source.getSheetByName('ALL Stages+Pit').getRange('H3:M21');
var desrg=sh.getRange('C33');
srcrg.copyTo(desrg);
}
}
function createOnMyEditTrigger() {
var ss=SpreadsheetApp.getActive();
ScriptApp.newTrigger('onMyEdit').forSpreadsheet(ss.getId()).onEdit().create();
}
Stage 3 Code:
function onMyEdit(e) {
var sh=e.range.getSheet();
if(sh.getName()!='Fellowship Tracking')return;
if(e.range.columnStart==7 && e.range.rowStart==31 && e.value=='Stage 3') {
var srcrg=e.source.getSheetByName('ALL Stages+Pit').getRange('N3:S21');
var desrg=sh.getRange('C33');
srcrg.copyTo(desrg);
}
}
function createOnMyEditTrigger() {
var ss=SpreadsheetApp.getActive();
ScriptApp.newTrigger('onMyEdit').forSpreadsheet(ss.getId()).onEdit().create();
}
PIT Code:
function onMyEdit(e) {
var sh=e.range.getSheet();
if(sh.getName()!='Fellowship Tracking')return;
if(e.range.columnStart==7 && e.range.rowStart==31 && e.value=='PIT') {
var srcrg=e.source.getSheetByName('PIT Sheet').getRange('B5:F17');
var desrg=sh.getRange('C33');
srcrg.copyTo(desrg);
}
}
function createOnMyEditTrigger() {
var ss=SpreadsheetApp.getActive();
ScriptApp.newTrigger('onMyEdit').forSpreadsheet(ss.getId()).onEdit().create();
}