guagay_wk
guagay_wk

Reputation: 28030

How to return comma-delimited string of range of cells in Google Sheets?

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?

Upvotes: 0

Views: 3271

Answers (2)

wchiquito
wchiquito

Reputation: 16551

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

Upvotes: 2

Serge insas
Serge insas

Reputation: 46792

have you tried something like that ?

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

Upvotes: 1

Related Questions