I am trying to copy the values only from a cell containing the function NOW(). For everything I try the target cell is empty :-(
I have tried:
spreadsheet.getRange('K1').activate();
spreadsheet.getCurrentCell().setValue('Erstellt am:');
spreadsheet.getRange('P1').activate();
spreadsheet.getCurrentCell().setFormula('=NOW()');
spreadsheet.getRange('N1').activate();
spreadsheet.getRange('P1').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
spreadsheet.getActiveRangeList().setNumberFormat('dd.MM.yyyy HH:mm:ss');
The result is that cell N1 is empty. If I add the statement:
spreadsheet.getCurrentCell().setValue('OTTO');
Then the cell N1 gets the value OTTO as expected.
I also tried outsourcing the logic into a separate function like this:
function COPY_DATE() {
var spreadsheet = SpreadsheetApp.getActive();
spreadsheet.getRange('N1').activate();
spreadsheet.getRange('P1').copyTo(spreadsheet.getActiveRange(), SpreadsheetApp.CopyPasteType.PASTE_VALUES, false);
spreadsheet.getActiveRangeList().setNumberFormat('dd.MM.yyyy HH:mm:ss');
};
This did not work either.
I also tried this way:
var source = spreadsheet.getRange ('P1');
source.copyTo (spreadsheet.getRange ('N1'), {contentsOnly:true});
Everything to no avail. I would really like to know what's going on here and appreciate any feedback.