Automatically sort records in a spreadsheet immediately after entering a value

I want to automatically sort the values โ€‹โ€‹in google spreadsheet as soon as I enter the value in the cell. The following is an example:

| S. No. | Task | Value | | 1 | Task 1 | $$ | | 2 | Task 2 | $$$ | | 3 | Task 3 | $$$$ | | | | | 

In the above table, as soon as I enter the value in the Task 3 field, I want it to return, and the first should end. I do not want to do this manually, sorting every time.

+6
source share
2 answers

Like Chris Hickโ€™s suggestion, you can enter your data in any order and copy the sorted copy. Since your example looks well ordered (upstream), I assumed that you want it to be ordered in descending order (on S. No. ), and the one that is in A1:

 =query(A:C,"Select * where A is not NULL order by A desc") 

Add a couple of entries 9 in A5, 8 in A6, and the resulting list will be ordered 9,8,3,2,1.

+1
source

You can use a script to automatically sort the table. To do this, go to the tools> script editor. This will open a new window.

Delete the code you see and paste below:

 function onEdit(event) { var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var cellColumn = sh.getActiveRange().getColumnIndex(); var currentSheet = sh.getName(); if ((cellColumn == 3) && currentSheet == "enter sheet name here") { var range = sh.getRange("A2:C"); range.sort({column:2, ascending:false}); } } 

You will need to change โ€œenter sheet name hereโ€ to the name of the sheet you want to sort. Be sure to leave quotation marks.

If you want to change the sort so that it grows, change the last line from

 ascending:false 

to

 ascending:true 

If you want to change the range of sorted data, you can do this in the line above. It is currently set to sort the range A2:C

+1
source

All Articles