-
Notifications
You must be signed in to change notification settings - Fork 15
/
splitCellToRows.gs
21 lines (19 loc) · 753 Bytes
/
splitCellToRows.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
function splitCellToRows() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sheet = ss.getSheetByName([YOUR SHEET]);
const lastRow = sheet.getLastRow();
const lastColumn = sheet.getLastColumn();
const range = sheet.getRange(1, 1, lastRow, lastColumn);
const rows = sheet.getDataRange().getValues();
const new_sheet = ss.insertSheet('result_' + Date.now());
const columnToSplit = 6;
const delimiter = ";";
let new_rows = [];
new_sheet.appendRow(rows[0].concat("new_split_column"));
for (i = 2; i <= lastRow; i++) {
let new_rows = sheet.getRange(i, columnToSplit).getValue().split(delimiter);
for (j = 0; j < new_rows.length; j++) {
new_sheet.appendRow(rows[i - 1].concat(new_rows[j].trim()));
}
}
}