Reputation: 113
In my Google sheet, I have 2 columns, A and B, which I would like to sort descending by values of Column B. This I know can be done using filter
/sort
options in sheets. This works as expected but this is a manual step that should be repeated every time data in column B changes.
I would like all rows to be automatically sorted when data in Column B changes. Any ideas to do this?
Example of data in column A and B
Team Score
Team A 13
Team C 12
Team B 11
Team D 5
Upvotes: 1
Views: 2402
Reputation: 1
add this script to your sheet:
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("Sheet1");
var range = sheet.getRange("A1:Z");
function onEdit(e) {
range.sort([{column: 2, ascending: false}]);
}
Sheet1
= name of the sheetA1:Z
= range to be sortedcolumn: 2
= column Bascending: false
= descendingUpvotes: 1