Agnes
Agnes

Reputation: 21

How to make a button to jump to a specific cell in another sheet in Google Spreadsheet?

I have a Google spreadsheet with many sheets and a table of contents. Is there some way to create a button in the main sheet so that with a click one can go directly to the cell in another sheet?

I figured out the way to make button and assigned the script to the button.

I modified a script to become like this, but I have problem on the last line, what should I do?

function goToSheet2b() {
  goToSheet("8601-10!N1");
}

function goToSheet(sheetName) {
  var sheet = SpreadsheetApp.getActive().getSheetByName(sheetName);
  SpreadsheetApp.setActiveSheet(sheet);
}

PS: 8601-10 is the name of the other sheet I need to go to.

Thank you for your help.

Upvotes: 2

Views: 22850

Answers (1)

Punchlinern
Punchlinern

Reputation: 754

You can't have the cell reference in the sheet name. You have to send them as separate variables.

function goToSheet2b() {
  // 1 = row 1, 14 = column 14 = N
  goToSheet("8601-10", 1, 14);
}

function goToSheet(sheetName, row, col) {
  var sheet = SpreadsheetApp.getActive().getSheetByName(sheetName);
  SpreadsheetApp.setActiveSheet(sheet);
  var range = sheet.getRange(row, col)
  SpreadsheetApp.setActiveRange(range);
}

Upvotes: 4

Related Questions