Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

192
Views
How to pass named range to custom function as cell and not as range?

In Google Sheets "Apps Script" i defined a custom function that receives a format, and some values, then replaces the values into the format's placeholders and return it.

function PRINT_DETAILS(format, productName, quantity) {
    /* format expects a string with placeholders like: "{productName} {quantity}"
       product: expects a string
       quantity: expects an integer
    */
}

In the Products "table" there are the following columns: name, quantity, price, etc. Each of those have their own named range.

I defined a "print" column where i call the function like this: = PRINT_DETAILS("{productName} {quantity}"; Products.Name; Products.Quantity)

The problem is that my function is receiving the whole named range, and not just the cell value of the same row. i.e. im receiving all the products names and all the products quantities...

I successfully used named ranges as cell values in lot of ways: adding them, in "IF" conditions, concat operator "&", etc. Even in standard functions calls.

Thats why i believe there would be a way to do the same in custom functions.

I wouldnt like to sacrifice readability using cell references like A1 or something.

So im looking for a way to constrain arguments, or get my desired values in a non too-hacky way. Also if we could get a look into Google Sheets source code, maybe those standard functions are also implemented in JavaScript and they have this already solved.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Description

Excel has a feature where a value of a named range can be passed to a custom formula corresponding to the row the formula is in. Unfortunately Google Sheets does not have the feature. Instead you need to get the row number toof the formula.

Note that this assumes the named ranges start in row 1 and the formulas are on that same row in any sheet.

Thanks to Mike Steelson I have modified the script slightly to improve the script. But not the screeen shot.

=PRINT_DETAILS("{productName} {quantity}",Products.Name,Products.Quantity)

Screen shots

enter image description here

Script

function PRINT_DETAILS(format,productName,quantity) {
  try {
    var row = SpreadsheetApp.getActiveRange().getRow();
    return [productName[row-1],quantity[row-1]];
  }
  catch(err) {
    return err.message;
  }
}

Reference

  • https://support.google.com/docs/thread/92023000?authuser=0&hl=en
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!