I use a script that allows me to delete the empty rows in the middle of my table and also constantly adds rows at the bottom so that I can keep filling it. Everything works perfectly. I just want the script to run automatically if I delete or add a value in the "C" column. And also, if possible, add a function in my menu bar with onOpen(e) in case the script doesn't execute and I have to run it manually. This is my Sheets:
This is the script:
function removeEmpty() {
const sh = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Suivi Clients');
const empty_rows = [];
const lastRow = sh.getLastRow()
const data = sh.getRange("C6:G" + lastRow).getValues();
for (var i in data) if (data[i].join('') == '') empty_rows.push(+i + 6);
empty_rows.reverse().forEach(x => sh.deleteRow(x));
sh.insertRowsAfter(lastRow - empty_rows.length, 5)
var rng = sh.getRange('A6:Z6')
rng.copyTo(sh.getRange('A' + (lastRow - empty_rows.length + 1) + ':Z' + (lastRow - empty_rows.length + 5)), SpreadsheetApp.CopyPasteType.PASTE_FORMAT, false);
// H-I-J-K-L
var rng = sh.getRange('H' + (lastRow - empty_rows.length) + ':L' + (lastRow - empty_rows.length))
rng.copyTo(sh.getRange('H' + (lastRow - empty_rows.length + 1) + ':L' + (lastRow - empty_rows.length + 5)), SpreadsheetApp.CopyPasteType.PASTE_FORMULA, false);
// O
var rng = sh.getRange('O' + (lastRow - empty_rows.length) + ':O' + (lastRow - empty_rows.length))
rng.copyTo(sh.getRange('O' + (lastRow - empty_rows.length + 1) + ':O' + (lastRow - empty_rows.length + 5)), SpreadsheetApp.CopyPasteType.PASTE_FORMULA, false);
// Q-R-S-T-U
var rng = sh.getRange('Q' + (lastRow - empty_rows.length) + ':U' + (lastRow - empty_rows.length))
rng.copyTo(sh.getRange('Q' + (lastRow - empty_rows.length + 1) + ':U' + (lastRow - empty_rows.length + 5)), SpreadsheetApp.CopyPasteType.PASTE_FORMULA, false);
// X-Y
var rng = sh.getRange('X' + (lastRow - empty_rows.length) + ':Y' + (lastRow - empty_rows.length))
rng.copyTo(sh.getRange('X' + (lastRow - empty_rows.length + 1) + ':Y' + (lastRow - empty_rows.length + 5)), SpreadsheetApp.CopyPasteType.PASTE_FORMULA, false);
}