I have a Google Sheet where the top 3 rows, including column headers, are frozen. When user data is entered in cell A1, my script copies it to a cell in a different row of the spreadsheet, and activates that cell so it will be visible to the user, even if that row had been scrolled out of view. All that works properly, until I add the next line of code -to reactivate cell A1 for the next user input.
Here's the sample script I am using to troubleshoot the problem. I am very new to Google Apps Script. Any help will be appreciated.
function onEdit(e) {
// Practice script: scroll to show
// a cell where new data was just added
var range = e.range;
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
var cellAddress = e.range.getA1Notation();
var inputCell = 'A1';
var inputData = sheet.getRange(inputCell).getValue(); // get user input
// If edited cell was A1, scroll to cell (5,5) and record user input
if (cellAddress === inputCell) {
sheet.getRange(5,5).activate();
sheet.getRange(5,5).setValue(inputData);
// then reactivate inputCell
// If the following line is executed, the sheet won't scroll to (5,5)
// sheet.getRange(1,1).activate();
}
}
SpreadsheetApp.flush();
between your.activate()
lines. – ross