In this article, we will show you exactly how to set up Google Sheets to open to the last edited cell. Simply follow the steps below.
Follow the steps below to have Google Sheets open to the last edited cell.
Go to the “Extensions” menu and select “Apps Script.” This opens a new window where you can write your custom script directly in Google Sheets.
No need to download anything as you can work within this built-in editor.
Delete any existing code in the script editor and paste the following:
function onEdit(e) {
const sheet = e.source.getActiveSheet();
const range = e.range;
const lastEditedCell = range.getA1Notation();
const lastEditedSheet = sheet.getName();
PropertiesService.getScriptProperties().setProperty('lastEditedCell', lastEditedCell);
PropertiesService.getScriptProperties().setProperty('lastEditedSheet', lastEditedSheet);
}
function openToLastEditedCell() {
const properties = PropertiesService.getScriptProperties();
const lastEditedCell = properties.getProperty('lastEditedCell');
const lastEditedSheet = properties.getProperty('lastEditedSheet');
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(lastEditedSheet);
SpreadsheetApp.setActiveSheet(sheet);
sheet.setActiveRange(sheet.getRange(lastEditedCell));
}
This code saves the last edited cell and sheet name whenever you make an edit.
Click the disk icon to save the script. Name your project something recognizable, like “Last Edited Cell Tracker.”
Click on the clock icon (Triggers) in the left sidebar. Click “Add Trigger,” select the "openToLastEditedCell" function, and set it to run on the event type “On open.” After that, click “Save” to confirm.
This ensures the script runs every time you open the document.
When prompted to send an email, enter an email address to receive notifications about changes. Make sure to follow this step, as it is important for moving on to the next step.
Make an edit in your Google Sheet, close the document, and reopen it. If set up correctly, it should take you to the last edited cell.
You can check if the script works by editing a cell and then reopening the file.
We hope that you now know how to open Google Sheets at the last edited cell. If you enjoyed this article, you might also like our articles on how to request edit access in google sheets and how to copy a google sheet.