I have a spreadsheet with two sheets called Robin
and Lucy
. I've made/found/mangled a script to sort the data on the sheet each time I add some data to column A:
function onEdit(event){
var sheet = event.source.getActiveSheet();
var editedCell = sheet.getActiveCell();
var columnToSortBy = 1;
var tableRange = "a2:I30";
if(editedCell.getColumn() == columnToSortBy){
var range = sheet.getRange(tableRange);
range.sort( { column : columnToSortBy } );
}
}
This script works well but I only want it it be applied on the first sheet, Robin
. The data in the second sheet, Lucy
, isn't the same so I'm going to create another script for a different range for that one, once I get my head around this problem.
I think I need to use the getSheetByName("Robin")
but I can't seem to get it to work.