I have a Google sheet (Form responses) with the following structure:
| Timestamp | Field 1 | Field 2 | Field 3 | Field 4 || | | | | 4 || | | | 2 | || | | | 1 | || | | | | 5 || | | | 3 | |I wish to have a script that sorts the rows but considering the contents of two columns (3 and 4 in the example) combined. Field 3 and 4 are never filled-in in the same row.
To be clear this is the result I'm after:
| Timestamp | Field 1 | Field 2 | Field 3 | Field 4 || | | | 1 | || | | | 2 | || | | | 3 | || | | | | 4 || | | | | 5 |Is it possible?If not, I would consider a script that would copy the contents of Field 4 in Field 3 IF field 3 is empty and then sort. I'm open to other suggestions.
At the moment, I'm using this script which sorts the content of the columns SEPARATELY.
function autoSort(sheet) { var NUMBER_OF_HEADER_ROWS = 1; var range = sheet.getDataRange(); if (NUMBER_OF_HEADER_ROWS > 0) { range = range.offset(NUMBER_OF_HEADER_ROWS, 0); } range.sort([{column: 9, ascending: true}, {column: 12, ascending: true}]);}function onOpen(e) { var sheet = e.source.getActiveSheet(); // get the default sheet when the spreadsheet opens autoSort(sheet);}