1

I am relatively new to creating custom functions in Google Scripts.

I need to be able to pass in an array of ranges into a function.

Please let me know if I am approaching this incorrectly.

I am getting a parse error when I reference it in Google Sheets as =ConcatEach(["A1:A2","B1:B2"],"$"]) (Without the quotes.)

(Also, the values are arbitrary. I know dollar signs go before the value.)

Anyway, here is what I have:

 function ConcatEach(rangeString, concatString)
 {
  //var rangeString = ["A1:A2","B1:B2"];
  //var concatString = "$";

  var sheet = SpreadsheetApp.getActiveSpreadsheet();
  var rangeValues=[];
  for(i=0;i<rangeString.length;i++)
  {
    var range = sheet.getRange(rangeString[i]);
    rangeValues.push(range.getValues());
  }

  //Logger.log(rangeValues);

  for(i=0;i<rangeValues.length;i++)
  {
    for(j=0;j<rangeValues[i].length;j++)
    {
      if(rangeValues[i][j] != "")
      {
        rangeValues[i][j] = rangeValues[i][j] + concatString;
      }
    }
  }
  return rangeValues;
}

Any help would be super appreciated! Thank you!

1 Answer 1

1

you may pass rangeString as string with commas:

"A1:A2,B1:B2"

and then use JavaScript String split() Method:

var array =  rangeString.split(",");
Logger.log(array); // you'll get array ['A1:A2', 'B1:B2']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.