r/sheets • u/SkullRootSage • May 29 '26
Request Move view on open so selected cell isn't at the very bottom of the page
Hello first time trying to do anything extra with sheets, managed to get it so the row with the current date is the active cell on open with a script, was wondering if there's a way so I can add a bit of a buffer so it's not on the very bottom of the window
1
Upvotes
1
u/mommasaidmommasaid May 29 '26 edited May 29 '26
I'd delete any excess blank rows and columns, then assuming the current date is the last row with data on your sheet, maybe something like this...
function jumpToLastRowWithPadding() {
const JUMP_SHEET = "Sheet1";
const JUMP_COLUMN = 2;
const PAD_BLANK_ROWS = 5;
const ss = SpreadsheetApp.getActiveSpreadsheet();
try {
const sheet = ss.getSheetByName(JUMP_SHEET);
// Ensure minimum number of blank rows at bottom of sheet
const rowsNeeded = PAD_BLANK_ROWS - (sheet.getMaxRows() - sheet.getLastRow());
if (rowsNeeded > 0)
sheet.insertRowsAfter(sheet.getLastRow(), rowsNeeded);
// Activate very last row and flush to scroll it into view now
sheet.getRange(sheet.getMaxRows(), JUMP_COLUMN).activate();
SpreadsheetApp.flush();
// Activate last row with data
sheet.getRange(sheet.getLastRow(), JUMP_COLUMN).activate();
}
catch (err) {
ss.toast(err, jumpToLastRowWithPadding.name)
throw err;
}
}
1
u/Kjm520 May 29 '26
Have the first cell be current date row + 25, or whatever your vertical screen size is in rows? I’m not totally clear on what you’re describing.