2

I have the following custom function I've built to basically reproduce a needle haystack type of functionality

function ListBy (Range, Range2, needle) {
  var holder = [];
  if(typeof Range != 'object') {
    throw "expected Range for input saw" + typeof Range;
    return false;
  } for(var i = 0; i < Range.length; i++) {
    if(Range[i] == needle) {
          holder.push(Range2[i]);
    }
  }

  return holder;
}

This script works perfectly when executed on one sheet, for instance

=ListBy(A1:A5, B1:B5, "needle");

But if I try and pass in data from another sheet like so

=ListBy('sheet1'!A1:A10, 'sheet1'!A1:A10, "needle")

I get a reference of range error. Why would this be the case?

1 Answer 1

2

You added single quotes to the sheet references:

=ListBy('sheet1'!A1:A10, 'sheet1'!A1:A10, "needle")

If you leave those:

=ListBy(Sheet1!A1:A10, Sheet1!A1:A10, "needle")

then your script works as planned.

Screenshot

Sheet2:
enter image description here

Sheet1:
enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.