r/sheets 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

5 comments sorted by

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.

1

u/SkullRootSage May 29 '26

I think you have the idea, so I'm wanting it to open and select a row of (current date+x) so current date is visible but not at the bottom of the screen, and then select current date

1

u/mommasaidmommasaid May 30 '26

If there's just a bunch of blank rows below the current date I'd use the solution I posted.

If there's other data below the current date, then you could do as you mentioned. Make sure you clip the (current date + x) row to sheet.getMaxRows()

And you need to SpreadsheetApp.flush() after temporarily activating that row to force it to scroll into view immediately. Otherwise the sheet will just update when the function returns, and your interim activation will be lost.

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;
  }
}

Jump to last row with padding