Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Created April 2, 2015 17:40
Show Gist options
  • Save primaryobjects/2f1a55afa341458f08ab to your computer and use it in GitHub Desktop.
Save primaryobjects/2f1a55afa341458f08ab to your computer and use it in GitHub Desktop.
Google Spreadsheet script to remember the last edited cell position and automatically scroll to it when opening the document.
//
// Remember Last Edited Cell Position in Google Spreadsheets
//
// Install:
// 1. Open spreadsheet in Google Drive.
// 2. Click Tools->Script editor.
// 3. Paste the contents of this file into the text field.
// 4. Click Run->install
// 5. When prompted for permission, click OK.
// 6. Click Run->install a second time. Done!
// https://productforums.google.com/d/msg/docs/WLRi5_t1X18/kwnAeHZO4g8J
// https://productforums.google.com/d/msg/docs/WLRi5_t1X18/fueOWl7Fc1IJ
function install() {
var ss = SpreadsheetApp.getActive();
ScriptApp.newTrigger("myfunction").forSpreadsheet(ss).onEdit().create();
}
function myfunction() {
var sheet = SpreadsheetApp.getActiveSheet();
var sName = sheet.getName();
var currentCell = sheet.getActiveCell().getA1Notation();
ScriptProperties.setProperty("sheetName", sName);
ScriptProperties.setProperty("cell", currentCell);
}
function onOpen() {
var lastModifiedSheet = ScriptProperties.getProperty("sheetName");
var lastModifiedCell = ScriptProperties.getProperty("cell");
SpreadsheetApp.getActiveSpreadsheet().getSheetByName(lastModifiedSheet).getRange(lastModifiedCell).activate();
}
@bhavik90
Copy link

get message saying line 22 is deprecated.

@kannanjgithub
Copy link

Works on computer but not on Android. Can you please provide a solution for Android Sheets App as well?

@Sanskriti24
Copy link

Can you please explain the code because it is not showing any desired output to get last edited cell.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment