0
votes

I'm trying to make a navigation menu to jump to certain cells in my sheet since it's very long. This could be done by the following code:

function jumpToCellB4() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = ss.getSheets()[0];
  var range = sheet.getRange("B4");
  sheet.setActiveSelection(range);
}

function onOpen() {
    SpreadsheetApp.getUi()
        .createMenu('Navigation')
        .addItem('Go to B4', 'jumpToCellB4')
        .addToUi();
}

However, I delete and insert rows all the time. This makes it impossible to use the function above, because cells are moving around.

Is there a unique identifier for a cell which can be used to link to, even if rows are inserted or deleted?

1
use onChange() to add/sub the 4 in B4 using PropertiesServiceTheMaster
"unique identifier for a cell" - use named range?Kos

1 Answers

3
votes

Use a named range instead of a specific address location. Then you can modify your code to something like:

function jumpToTestCell() {
  var ss = SpreadsheetApp.getActiveSpreadsheet();
  var testCell = ss.getRangeByName("TestCell");
  testCell.activate();
}

function onOpen() {
  SpreadsheetApp.getUi()
  .createMenu('Navigation')
  .addItem('Go to Test Cell', 'jumpToTestCell')
  .addToUi();
}