I have a list of ranges where depending on the cell value, a checked checkbox (Completada) or an unchecked checkbox (No completada) should be inserted.
The problem I have is that the script places checkbox in the entire list of ranges, it does not ignore empty cells or cells that do not contain those specific values.
It’s probably a very slight problem, but I can’t fix it.
This is my actual code:
function checkboxVistaMensual_comparacion() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const targetSheet = ss.getSheetByName('Calendario'); // Hoja Destino
var rangesCheckbox = targetSheet.getRangeList(['F6:F98', 'I6:I98', 'L6:L98', 'O6:O98', 'R6:R98', 'U6:U98', 'X6:X98']);
var rangesCheckboxVal = rangesCheckbox.getRanges();
var c = 'Completada';
var nc = 'No completada';
var valores = []
rangesCheckboxVal.forEach((row)=> {
if ( row.valueType == SpreadsheetApp.ValueType.CHECKBOX ) return;
if ( row == '' ) return;
if ( row == c ){
valores.push(c);
} else {
if ( row == nc ){
valores.push(nc);
}
}
})
rangesCheckbox.insertCheckboxes(c, nc);
}