I have data that looks like this in Sheet 2 of GS:
Company|State|ID|........|Order#1|Description 1|Qty 1|Order#2|Description #2|Qty #2||Order#3|Description #3|Qty 3|
but I would like for it to look like this in Google Sheets on Sheet 3:
Company|State|ID|........|Order#1|Description 1|Qty 1|
Company|State|ID|........|Order#2|Description 2|Qty 2|
Company|State|ID|........|Order#3|Description 3|Qty 3|
I have already taken a stab of this on script editor in Google Sheets, but I can't seem to make it work:
// http://webapps.stackexchange.com/a/40060/29140
function SPLIT() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sh0 = ss.getSheets()[1], sh1 = ss.getSheets()[2];
// get data from sheet 2
var data = sh0.getDataRange().getValues();
// create array to hold data
var aMain = new Array();
// iterate through data and add to array
for(var i=1, dLen=data.length; i<dLen; i++) {
for(var j=1; j<61
; j++) {
aMain.push([data[i][1],data[i][j],data[i][61]]);
}
}
// add array of data to third sheet
sh1.getRange(2, 1, aMain.length, 28).setValues(aMain);
}
Did I do something wrong with the last line of code? Is that why I can't run it? Could someone help me understand what I did wrong?