I made this script that basically copies the table in the first sheet and pastes it in the second one exactly 3 rows after the last one. The problem is that everything works but when I paste the formulas in the targeted cells of the F column the cells show the error "#NAME?". This is particularly weird since if I copy the content of that cell and paste it somewhere else it works fine. Why? What can I do to resolve this problem? Here' the code:
function inserisciDatabase() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var source = ss.getSheets()[0];
var destination = ss.getSheets()[1];
var startRow = destination.getLastRow()+3;
var numRows = destination.getLastRow()+16;
var sourceRange = source.getRange("A6:K18");
sourceRange.copyFormatToRange(destination, 1, 11, startRow, numRows);
sourceRange.copyValuesToRange(destination, 1, 11, startRow, numRows);
//var sourcePresenteRange = source.getRange("F6:F18");
//var formulas = sourcePresenteRange.getFormulas();
var b = 0;
for(a = startRow; a < numRows; ++a){
var cell = destination.getRange(a,4);
var cellVal = cell.getValue();
if(cellVal === true){
cell.insertCheckboxes();
cell.check();
}
else if(cellVal === false){
cell.insertCheckboxes();
}
var formulaRange = destination.getRange(a,6);
var formula = '=SE(VAL.VUOTO(E'+a+');"";SE(OGGI()>=DATA.MESE(E'+a+';-1);"SCADENZA";"REGOLARE"))'
formulaRange.setValue(formula);
b = b + 1;
}
var rangeSollecitato = destination.getRange(startRow, 7, 13, 1);
rangeSollecitato.insertCheckboxes();
}
Here the sheets
Thank you so much in advance.
Gianmarco.
- If I copy the content of that cell and paste it somewhere else the formula works just fine.
- Refreshing the page doesnt't do anything
- Using "setValue" instead of "setFormula" changes nothing.
Thank you so much in advance.
Gianmarco.

