I need help creating an auto-sorting script in Google Sheets using the script editor. I want it to dynamically select rows based on whether a specific column contains empty cells, ensuring that rows with filled cells remain unchanged. Below is the sorting script I’ve discovered:
/**
* Automatically sorts the first column (excluding the header) in ascending order.
*/
function onRowEdit(event) {
var activeSheet = event.source.getActiveSheet();
var focusedCell = activeSheet.getActiveCell();
var sortColumn = 1;
var dataRange = "A2:T99"; // Define the range for sorting.
if (focusedCell.getColumn() == sortColumn) {
var sortRange = activeSheet.getRange(dataRange);
sortRange.sort({ column: sortColumn, ascending: true });
}
}
Thank you!