google sheets script onedit sort for multiple sheets

Solutions on MaxInterview for google sheets script onedit sort for multiple sheets by the best coders in the world

showing results for - "google sheets script onedit sort for multiple sheets"
Edoardo
11 Jun 2018
1function onEdit(event){
2  	var ss = SpreadsheetApp.getActiveSpreadsheet();
3  	var sheet = event.source.getActiveSheet().getName()
4  	var editedCell = event.range.getSheet().getActiveCell();
5	if(sheet=="Loan Inquiries"){
6  		var columnToSortBy = 2;
7  		var tableRange = "A3:T99"; //range to be sorted
8  		if(editedCell.getColumn() == columnToSortBy){   
9    		var range = ss.getActiveSheet().getRange(tableRange); 
10    		range.sort( { column : columnToSortBy, ascending: true } );
11  		}
12    }
13  	else if(sheet=="Deals in Escrow"){
14    	var columnToSortBy = 7;
15    	var tableRange = "A3:T99"; //range to be sorted
16  		if(editedCell.getColumn() == columnToSortBy){   
17     		var range = ss.getActiveSheet().getRange(tableRange); 
18    		range.sort( { column : columnToSortBy, ascending: true } );
19  		}
20    }
21  	else{return}
22}