I have a range in Google Sheets that contains a combination of values and formulas scattered in various rows and columns. The sort needs to be custom and I wrote a custom sort function that extracts data and sorts the array. However when pasting the sorted result back I loose the formulas.
Is there a way to create a custom sort directly for the range without the set/get Values?
function orderMyRange() {
var sh = SpreadsheetApp.getActiveSpreadsheet();
var mySheet = sh.getSheetByName("MySheet");
var myRng = mySheet.getRange("A4:L500");
var myData = myRng.getValues();
myData.sort(orderCustom);
myRng.setValues(myData);
}
orderCustomisorderCustomfunction as-is - I suggested that you review the format expected by theRange#sortclass method, as it may resolve your issue simply.