Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Google spreadsheet with the cursor on last working cell

I would like that when I open any of my google spreadsheets the cursor be stepped on the last working cell (to remember the last position). Is this possible?

Thank you

like image 788
agusgambina Avatar asked Mar 06 '15 02:03

agusgambina


1 Answers

You can create a trigger that runs every time your spreadsheet is opened.

This can probably be written more concisely but this would be the simplest idea, saving your row and cell properties upon each edit, and then setting them on open. Visit the Properties Service page to get some more info on which users can access those properties.

This will return to the last cell edited, not the last cell where the cursor had been.

ToolsScript editor and paste the following:

function onEdit(e) {

  var ss = e.source
  var sheet = ss.getActiveSheet();
  var cell = ss.getActiveCell();
  var row = cell.getRow();
  var column = cell.getColumn();
  var sheet_name = sheet.getSheetName();
  var scriptProperties = PropertiesService.getScriptProperties();  

  scriptProperties.setProperty('row',row);
  scriptProperties.setProperty('column',column);
  scriptProperties.setProperty('sheet name',sheet_name);
}

function onOpen(e) {

  var properties = PropertiesService.getScriptProperties();

  var ss = e.source;
  var sheet_name = properties.getProperty('sheet name');
  var sheet = ss.getSheetByName(sheet_name);
  var row = properties.getProperty('row');
  var column = properties.getProperty('column');
  var cell = sheet.getRange(row,column);

  ss.setActiveSheet(sheet);
  ss.setActiveRange(cell);  
}  
like image 178
Dan Oswalt Avatar answered Sep 21 '22 19:09

Dan Oswalt