Last active
June 10, 2020 17:11
-
-
Save robomatic/3cae9db2fa393df508762f9fec87377f to your computer and use it in GitHub Desktop.
Google Sheets Split Cell CSV Values to Rows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// select the 1 or more rows to set the active range | |
function cellCSVSplitToRows() { | |
const sheet = SpreadsheetApp.getActiveSheet() | |
const aRange = sheet.getActiveRange() | |
let rowTracker = 0 | |
function setFeatures(range) { | |
const startIndex = range.getRowIndex() | |
// target the column with CSV content here | |
const fColIndex = 3 | |
const features = range.getCell(1,fColIndex).getValue().split(',').map(f => [f]) | |
const rows = features.length | |
const destRange = sheet.getRange(startIndex + 1, fColIndex, rows, 1) | |
const featureColumnRange = sheet.getRange(startIndex + 1, fColIndex, rows, 1) | |
sheet.insertRowsAfter(startIndex, rows) | |
destRange.setValues(features) | |
rowTracker += (rows + 1) | |
} | |
const arEnd = aRange.getLastRow() | |
const arStart = aRange.getRowIndex() | |
for(let i = arStart; i <= arEnd; i++) { | |
let currentStart = arStart + rowTracker | |
let r = sheet.getRange('Sheet1!A'+ currentStart + ':W' + currentStart) | |
setFeatures(r) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment