Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Last active June 30, 2022 15:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save primaryobjects/a9bf9ff1d2a7feb5ebd8888d67c0febb to your computer and use it in GitHub Desktop.
Save primaryobjects/a9bf9ff1d2a7feb5ebd8888d67c0febb to your computer and use it in GitHub Desktop.
Automatically scroll to the last row in a Google Sheets spreadsheet upon opening the file. Google Docs. Google Drive.
//
// Automatically scroll to the last row.
//
function selectLastRow() {
const sheets = SpreadsheetApp.getActive().getSheets();
// Set focus to the last active row on the first two sheets.
for (var sheetIndex = 0; sheetIndex < 2; sheetIndex++) {
// Get the sheet.
var sheet = sheets[sheetIndex];
// Set the active cell to the last cell in the first column.
var range = sheet.getRange(sheet.getLastRow() + 1, 1);
sheet.setActiveCell(range);
// Update the sheet.
SpreadsheetApp.flush();
}
// Set the first sheet as active.
SpreadsheetApp.setActiveSheet(sheets[0]).getRange(sheets[0].getLastRow() + 1, 1).activate();
}
function onOpen() {
selectLastRow();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment