You can create a trigger that runs every time your spreadsheet is opened.
Go to Extensions → Apps Script and paste the following:
function onOpen(e) {
var spreadsheet = e.source;
var sheet = spreadsheet.getActiveSheet();
var lastRow = spreadsheet.getLastRow();
if (sheet.getMaxRows() == lastRow) {
sheet.appendRow([""]);
}
lastRow = lastRow + 1;
var range = sheet.getRange("A" + lastRow + ":A" + lastRow);
sheet.setActiveRange(range);
}
Click the Save button, then close the script editor, and the spreadsheet.
Now, open your spreadsheet again. Give it a couple of seconds, and you should see that a new row is inserted at the end of your sheet, and that that row is selected.
I have created this spreadsheet to demonstrate - feel free to copy it (click File → Copy). You will need to run your own copy in order to see the script run successfully.
The script explained:
The onOpen
function name has a special meaning. See documentation.
It takes a single argument, an Event
object. Its source
property is a reference to the spreadsheet being opened. With the spreadsheet, we can do getLastRow()
to find the index of the last row that has content. getMaxRows()
gives us the max number of rows in the sheet, even empty ones. With that knowledge, we can see if the last row has content - if so, we append a new, empty row. Finally, we can create a range and call setActiveRange
on it, to move to the last row.
If you just want to move to the last line, not inserting anything, the script can be simplified as this:
function onOpen(e) {
var spreadsheet = e.source;
var sheet = spreadsheet.getActiveSheet();
var lastRow = spreadsheet.getLastRow();
var range = sheet.getRange("A" + lastRow + ":A" + lastRow);
sheet.setActiveRange(range);
}
Home
key.