Open Sheet to Last Used Tab / Range

 
Using onEdit, onOpen, and the Properties Service to open a Sheet to the last used tab and/or range
Important notes:
* Remember not to manually run the onEdit or onOpen functions – they will run automatically whenever the Sheet is edited or opened
* The Properties Service can only hold strings, so we have to use other Apps Script functions to convert the tab name string and range string into an actual tab and range value

Sheet (to copy from File then Make a copy):
https://docs.google.com/spreadsheets/d/1wPLC8US_Susq3q5STixES4Ac4dHl0UqNDMGkD1oMPzg

Script:
function onEdit(e){
PropertiesService.getScriptProperties().setProperty(‘lastOpenTab’,e.source.getActiveSheet().getName());
PropertiesService.getScriptProperties().setProperty(‘lastOpenR’,e.range.getA1Notation());
}

function onOpen(){
let sh = SpreadsheetApp.getActive();
let sheetName = PropertiesService.getScriptProperties().getProperty(‘lastOpenTab’);
let r = PropertiesService.getScriptProperties().getProperty(‘lastOpenR’);
let ss = sh.setActiveSheet(sh.getSheetByName(sheetName));
ss.setActiveRange(ss.getRange(r));
}

Connect with me:
• spencer.farris@gmail.com
• spencerfarris.me
• www.linkedin.com/in/spencer-farris/
• Twitter @FarrisSpencer
• Google Product Expert support.google.com/docs/profile/12305

Leave a Reply

Your email address will not be published. Required fields are marked *