r/GoogleAppsScript • u/OkDevelopment6063 • Sep 14 '22
Question Help With script please!
Hello, I would like to have this spread sheet preform two on edit commands. I want entry's to auto sort based on the date in column 6 and also give a time stamp in column 7 when column 6 is edited or new line is created. the two scripts I found online work fine by themselves but not together. I want them to both worth as the same time and also i want to get rid on the sheet specific criteria for the autosort function and for it to affect the whole document not just individual sheets. can anyone help me?
function onEdit(e) { var row = e.range.getRow(); var col = e.range.getColumn(); if(col == 1){ e.source.getActiveSheet().getRange(row,2).setValue(new Date()); } }
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("YM"); // SHEET NAME
var range = sheet.getRange("A2:O"); // RANGE TO SORT
function onEdit(e) {
range.sort([{column: 6, ascending: true}]); // COLUMN NUMBER TO SORT
}
2
u/DistributionNo997 Sep 15 '22
Wrote it will taking a shit on my phone, just copy your range.sort in the last line