Last active
June 30, 2022 15:06
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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