0

I have a spreadsheet with multiple email id's in it. I would like to split those email id's into multiple columns. I am able to split the values in first cell, But I'm not able to do it for the rest of the rows. There are more than 100 rows with comma separated email id's.

This is my code. Correct me if there is any mistake.

function myFunction() {

  var sheets = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

  var data = sheets.getDataRange().getValues();

  for(var i=0;i<data.length;i++){

    var cell = data[i][0].split(",");

    var row = sheets.getActiveCell().getRowIndex();
    var col = sheets.getActiveCell().getColumnIndex();

    sheets.getRange(row,col+1,1,cell.length).setValues([cell]);
  }


}

Thanks

Max Makhrov
  • 17,309
  • 5
  • 55
  • 81
Kanchan
  • 65
  • 2
  • 11

1 Answers1

0

Native formula

You may use formula in cell B1:

=split(A1, ",")

just copy it down.


Script

Try also using this script:

function splitRange(data, delimeter) {

var result = [];
var cell = [];

  for(var i=0; i<data.length; i++){

    cell = data[i][0].split(delimeter);

    result.push(cell);
  }

  return result;
}

use it as usual function in your worksheet:

=splitRange(A1:A5,",")
Max Makhrov
  • 17,309
  • 5
  • 55
  • 81
  • Thanks for the help..I have below spreadsheet which as list of site owners. I want to check which email id has owner access to sites. Like a single email id can have owner access to many sites. So i need that. Can you please tell me how can i do this using google app script? Here is the sheet lik https://docs.google.com/spreadsheets/d/1xeLZk1AKUCj7sbBrcAaJRl5MON2zkxVwcfssG3Wgzpw/edit#gid=0 – Kanchan Jun 09 '16 at 17:38