0
votes

Using the following code allows the last edited cell to open when reopening a google spreadsheet.

function setTrigger() {
  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();
  UserProperties.setProperty("mySheetName", sName);
  UserProperties.setProperty("myCell", currentCell);
}

function onOpen() {
  var lastModifiedSheet = UserProperties.getProperty("mySheetName");
  var lastModifiedCell  = UserProperties.getProperty("myCell");
  SpreadsheetApp.getActiveSpreadsheet().getSheetByName(lastModifiedSheet).getRange(lastModifiedCell).activate();
}

I have a cell which has

=today()

Which updates so the code doesn't open the last row of my spreadsheet, but opens in the cell that updates with today().

How would I update the script to open the spreadsheet at my last edited cell in the last row of the spreadsheet?

1
can you share your spreadsheet?Blexy
Here is the link, thanks.linkhamm44

1 Answers

1
votes

Can you try this:

function myFunction() {
  var sheet = SpreadsheetApp.getActiveSheet();
  var sName = sheet.getName();
  var currentCell = sheet.getActiveCell().getA1Notation();
  var temp = "";
  if (currentCell != "A1") {temp = currentCell;} 
 UserProperties.setProperty("mySheetName", sName);
  UserProperties.setProperty("myCell", temp);
}

I added a temp variable and am doing a check (assuming only A1 has the today() function) before updating temp. Seems to work.