How to sort columns on the fly while editing in Google Sheets

Written by Akshay Chavan on #arccoder Blog

01 Nov 2016


In the previous post How to create a button to sort columns in Google Sheets we saw how you can sort a column with a click of a button.

Pushing a button to get things done is so not 2016. It would be great if the list sorts itself when you modify or add data to the column.

And its very simple to do that. Just add the sort code into the function named onEdit().

function onEdit() {
  SpreadsheetApp.getActiveSheet().getRange(2,1,8,2).sort( {column: 2,ascending: true} );
  SpreadsheetApp.getActiveSheet().getRange(2,3,7,2).sort( {column: 4,ascending: true} );
  SpreadsheetApp.getActiveSheet().getRange(2,5,8,2).sort( {column: 6,ascending: true} );
}

Thats it you are done.

You may also check the range of the data that was edited by using onEdit(e) and depending on the range call a specific function.




Related Posts

Edge detection explained in 1D : 15 Jan 2017
How to create a button to sort columns in Google Sheets : 30 Oct 2016
How to use meanshift function from FastCV : 04 Oct 2016

@ All Rights Reserved.