Cursor At Last Edit Cell in Spreadsheet

135 views
Skip to first unread message

Swapnil Naik

unread,
Apr 24, 2023, 2:08:24 AM4/24/23
to Google Apps Script Community
Hello,

I am looking for a script, which will automatically keep the cursor at position of Last edit.

Kindly suggest

Web Dev

unread,
Apr 24, 2023, 12:41:59 PM4/24/23
to Google Apps Script Community
Google Apps Script doesn't support the cursor and its position in Google Sheets. It does have such support in Google Docs, however:

As for Google Sheets you can implement  the following:
1) Use PropertiesService to cache your data set (sheet name and range) in the memory onEdit()
2) Use PropertiesService to retrieve and apply the info onOpen()

function onOpen() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const rangePosition = PropertiesService.getUserProperties().getProperty('lastEditPosition');
if (rangePosition) {
rangePosition = JSON.parse(rangePosition);
ss.setActiveSheet(ss.getSheetByName(rangePosition.lastEditSheet));
ss.setActiveRange(ss.getRange(rangePosition.lastEditRange));
}
}
function onEdit(e) {
const range = e.range;
const sheet = range.getSheet();
PropertiesService.getUserProperties().setProperty('lastEditPosition', JSON.stringify({
lastEditSheet: sheet.getName(),
lastEditRange: e.range.getA1Notation(),
}));
}
Reply all
Reply to author
Forward
0 new messages