0
votes

I am using Google Sheets and writing a custom function that takes in a range of cells as parameter and returns a string that adds a delimiting comma to the contents of the cell.

For example, we have a range B1:B2 where cell B1 contains "B1_contents" and cell B2 contains "B2_contents". The function should return "B1_contents, B2_contents".

How can this be done in Google Sheets using Google Apps Script?

2

2 Answers

2
votes

You can try the following:

function rangeToStringSep(range, sep) {
  return range.toString().split(',').join(sep);
}

Use:

=rangeToStringSep(B1:B3; ", ")

UPDATE

function rangeToStringSep1(range, sep) {
  return range.join(sep);
}

enter image description here

1
votes

have you tried something like that ?

function toCommaSepStrings(values){
  return values.toString();
}