Решение с примером тут
https://t.me/google_spreadsheets_chat/251090
function formSendAction() {
const book = SpreadsheetApp.openById('1EbRQ1yV0upNFW11fuyfl3Bts7OTJ9rSAN2kiBekhzRg');
const data = book.getSheetByName('Лист2').getDataRange()
.getValues().slice(1)
.map(row => row[1])
.sort(stringCompare_)
.reverse();
const target = book.getSheetByName('Результат');
const targetData = target.getDataRange()
.getValues()
.map(row => row[0]);
const targetDataR = [...targetData].reverse();
const firstIndexR = targetDataR.findIndex(fioTarget => fioTarget !== '');
const firstIndex = targetData.findIndex(fioTarget => fioTarget !== '');
const lastIndexR = targetDataR.length - firstIndex;
data.forEach(fio => {
if (!targetData.includes(fio)) {
let index = targetDataR.findIndex(fioTarget => fioTarget !== '' && stringCompare_(fioTarget, fio) === -1);
if (index === -1) {
console.log(stringCompare_(targetData[firstIndex], fio), firstIndex, targetData[firstIndex], fio);
if (stringCompare_(targetData[firstIndex], fio) === 1) {
index = lastIndexR + 1;
} else {
index = firstIndexR - 2;
}
};
index = targetDataR.length - index + 2;
target.insertRowsBefore(index, 2);
target.getRange(index, 1).setValue(fio);
target.setRowHeights(index + 1, 1, 10);
}
});
}
function stringCompare_(a, b) {
return String(a).toLocaleLowerCase() < String(b).toLocaleLowerCase() ? -1 :
String(a).toLocaleLowerCase() > String(b).toLocaleLowerCase() ? 1 : 0;
};