Hi helpful contributors,
I have a response google sheet that has a set of datarange with different type of data values (screenshot) as below. Col2 Timestamp values are auto-generated upon user input in gform. I moved it as col2 (default is in col1) because I want to put the Quote ID as primary key col. Quote ID values are auto-generated based on google script that is triggered upon submission of gform:-
gresponse sheet with inconsistent sort
I supposed we would have the data range autosort by timestamp (and I need it significantly to sort by timestamp) but this is not happening consistently with mine. I already tried the below codes but still not working consistently too. But when I sort it manually in the sheet using the feature Filter to choose Timestamp column and then sort A->Z, it works fine. But that won't be effective for my requirements
Method 1 :
// this resulted as in the screenshot.
SortRange = "A2:AC";
SortOrder = [{column:2, ascending: true}];
function multiSortColumns(){
var range = msheet.getRange(SortRange);
range.sort(SortOrder);
}
Method 2 :
// some sorted, some not but still wrong and not ascending order.
SortRange = 2,1,sheet.getLastRow() - 1, sheet.getLastColumn();
SortOrder = [{column:2, ascending: true}];
function multiSortColumns(){
var range = sheet.getRange(SortRange);
range.sort(SortOrder);
}
Method 3
var sheet=SpreadsheetApp.getActiveSheet().sort(2);
// this doesn't sort by specific column we want and it includes sorting the header.
Please help to correct my code. Tqvm in advance.