Question

I'm trying to grab multiple cells from the last row of a Google Sheet upon a form submittal and copy them to a single cell in different sheet.

How do I combine the values in this array into one value? I'd like to put a comma and space between the data.

 var daterange = sourcesheet.getRange("H"+source_last_row+":Q"+source_last_row);

I'm not even sure the query is correct. The Logger says "Range". :\

I am grabbing the values below this in the script.

 var source_range6_values = daterange.getValues();
Was it helpful?

Solution

Logger returns "Range" because your variable is just a range. To get an array of the values in that range, you need to use the .getValues() method.

var daterange = sourcesheet.getRange("H"+source_last_row+":Q"+source_last_row);
var daterangeVals = daterange.getValues();

You can then use the .toString() method to convert the array to string.

That will return the values separated by a comma. As you want a comma and a space, you could then use the .replace() method on the string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top