I'm experiencing a weird issue. When I type text in a Google Sheet cell, then run a custom script (below) to get those values, it doesn't get the values I just type in. The values only become available once I move away from that cell (tab
or enter
).
var data = dataRange.getValues();
I'm not sure when the values actually get written to the cell. If I script a move away from that cell (below), I get the same issue.
var newRange = sheet.getRange("C4");
sheet.setCurrentCell(newRange);
Is there a way to write all the data to the sheet?
Can test using this code. Write some text to A1, run custom script and check the logs. If you don't move away from A1 before running script, logs will be empty.
function moveTest(){
var sheet = SpreadsheetApp.getActiveSheet();
var newRange = sheet.getRange("A2");
sheet.setCurrentCell(newRange);
var cellOfInterest = sheet.getRange("A1").getValue();
Logger.log(cellOfInterest);
}
Edit: same issue with setActiveSelection
instead of setCurrentCell
function runOne(){ SpreadsheetApp.getActive().toast(SpreadsheetApp.getCurrentCell().getValue()); }
I see the value in the toast immediately because the cell has lost focus when I run the function. – Cooper