79409094

Date: 2025-02-03 14:27:20
Score: 0.5
Natty:
Report link

Using getActiveRange() as Parameter

Agreeing @TheMaster you cannot directly assign a parameter into the menu item, Using the getActiveRange() and getValues() method as a workaround would help.

To use this workaround you just need to highlight the range of the value and it returns an array as the value of the parameter additionally using .toast() to check the return values of the highlighted cells.

function onOpen(e) {
  SpreadsheetApp.getUi()
    .createMenu('foo')
    .addItem('bar', 'foobar')
    .addToUi();
}

function foobar(bar = SpreadsheetApp.getActiveRange().getValues()) {
  return SpreadsheetApp.getActiveSpreadsheet().toast(bar);
}

Reference:

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