3
votes

We have checkboxes on a google form which feeds into a google sheet. Responses to checkboxes come comma separated and we are wondering if it's possible to have as new rows.

This is how the form populates the sheet:

[Col A] [Col B]
Name   Availability  
Larry  Monday  
Sergey Monday, Wednesday  
Sonali Thursday, Friday  

This is how we would like it:

[Col A] [Col B] 
Name   Availability  
Larry  Monday  
Sergey Monday  
Sergey Wednesday  
Sonali Thursday  
Sonali Friday  

Any ideas would be much appreciated, thanks!

2

2 Answers

2
votes

A little while ago I wrote a custom function in google apps script to deal with an identical situation. Here is the script.

/** 
* Splits the array by commas in the column with given index, by given delimiter
* @param {A2:B20}  range Range reference
* @param {2}  colToSplit Column index
* @param {","}  delimiter Character by which to split
* @customfunction
*/


function advancedSplit(range, colToSplit, delimiter) {
var resArr = [], row;
range.forEach(function (r) {
    r[colToSplit-1].replace(/(?:\r\n|\r|\n)(\d|\w)/g,", ").split(delimiter)
        .forEach(function (s) {
            row = [];
            r.forEach(function (c, k) {               
                row.push( (k === colToSplit-1) ? s.trim() : c);
            })
            resArr.push(row);
        })
    })
return resArr;
}

You can use the script as any other (built-in) formula by entering in the spreadsheet (assuming for example that the column to split is column D)

=advancedSplit(A1:Z, 4, ",")

I hope this helps ?

0
votes

You could try accomplish this task with formulas.

Suppose, there are two columns with data:

A      |       B
Name   | Availability

In this example data starts from second row. We need two formulas. First one makes list of Names:

=TRANSPOSE(SPLIT(JOIN("",ARRAYFORMULA(REPT(offset(A2,,,$G$1)&",",len(offset(B2,,,$G$1))-len(SUBSTITUTE(offset(B2,,,$G$1)," ",""))+1))),","))

Second formula makes list of checkbox Results:

=TRANSPOSE(SPLIT(join(", ",FILTER(B2:B;B2:B<>"")),", "))

Explanations:

  • A2 -- first cell with Names
  • B2 -- first cell with checkbox Results
  • $G$1 -- total number of rows. It could be formula:

    =COUNTA(A2:A)

This solution is complicated, but it works. Here's sample ,workbook.