Reputation: 47
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?
Upvotes: 0
Views: 4670
Reputation: 9571
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();
}
Upvotes: 3