I found this script from How can I apply a script to only one specific sheet within a spreadsheet to auto sort a column:
function onEdit(){
var sh0 = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
var editedCell = sh0.getActiveRange().getColumnIndex();
if(editedCell == 1) {
var range = sh0.getRange("B2:B7");
range.sort({column: 2, ascending: false});
}
}
However it's sorting by a single column and not keeping the data in other columns in line by row, so mixing all the data up.
I think I need to sort by sheet rather than range and found this page "Sorts a sheet by column", so I tried replacing:
range.sort({column: 2, ascending: false});
with
sheet.sort(2, false);
However now the script doesn't work.
How can I auto sort a single sheet by the values in one column, but keeping all the data in line?