79449753

Date: 2025-02-18 22:29:54
Score: 0.5
Natty:
Report link

Using .getUI() to create Menu

I'll post my Comment as an Answer.

@LimeHusky Tried getUI(); thanks for the comment!

Class UI helps users create a custom menu bar on the editors user interface enabling them to add personalized functions.

Sample Code:

function myFunction() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const ui = SpreadsheetApp.getUi();
  ui.createMenu('foo')
    .addItem('bar', 'foobar')
    .addToUi();
}

This might help to return to the cell A10 to A21 using for of loop.

function returnToLocation() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const location = sheet.getCurrentCell().getA1Notation().replace(/\D/g, '');

  const ranges = [
    {currentLocation:600,targetLocation:"A10"},
    {currentLocation:550,targetLocation:"A11"},
    {currentLocation:500,targetLocation:"A12"},
    {currentLocation:450,targetLocation:"A13"},
    {currentLocation:400,targetLocation:"A14"},
    {currentLocation:350,targetLocation:"A15"},
    {currentLocation:300,targetLocation:"A16"},
    {currentLocation:250,targetLocation:"A17"},
    {currentLocation:200,targetLocation:"A18"},
    {currentLocation:150,targetLocation:"A19"},
    {currentLocation:100,targetLocation:"A20"},
    {currentLocation:50,targetLocation:"A21"}
  ];

  for (const {currentLocation, targetLocation} of ranges) {
    if (location >= currentLocation) {
      sheet.getRange(targetLocation).activate();
      break; // Breaking the loop if matches
    }
  }

}

References:

Class UI

Reasons:
  • Blacklisted phrase (0.5): thanks
  • Long answer (-1):
  • Has code block (-0.5):
  • User mentioned (1): @LimeHusky
  • Low reputation (0.5):
Posted by: Lime Husky