javascript - google apps script combine duplicate rows by concatenating -
i'm trying combine duplicate rows using column h comparison. if duplicates found, want keep values of bottom row except in columns e-g,m,o want combine values. e.g. row 4 , 5 have matching values in h. new column e should have value e4 & e5 while new column has value a5.
this i'm working with:
function tryme() { var ss=spreadsheetapp.getactive(); var sh=ss.getactivesheet(); var rg=sh.getdatarange(); var row=rg.getrow(); var col=rg.getcolumn(); var va=rg.getvalues(); // values of data range == data comparing var na=[]; // create array var duplicate=true; // duplicate returns true compare wih !duplicate for(var i=0;i<va.length;i++) // each data item { duplicate=false; // start assuming no duplicates for(var j=0;j<na.length;j++) // each item in new array ?? na.length? thought started empty na[] ?? { if(va[i][1]==na[j][1]) // check if value of first item in data matches value of first item in new array { ss.appendrow([va[i][0],va[i][1],va[i][2],va[i][3],va[i][4] + '\n' + na[j][4],va[i][5] + '\n -- \n' + na[j][5],va[i][6],va[i][7],va[i][8],va[i][9],va[i][10],va[i][11],va[i][12],va[i][13],va[i][14] + '\n' + na[j][14],va[i][15],va[i][16],va[i][17]]) duplicate=true; // items match , duplicate returns true na[j]=va[i]; // create new array old array } } if(!duplicate) // if items not match, duplicate returns other var duplicate=true { na.push(va[i]); // place in array } } rg.clearcontent(); sh.getrange(row, col, na.length, na[0].length).setvalues(na); // set data value in new array }
this appends new row way want, (1) leaves blank row 'rg.clearcontent()' , (2) leaves matching bottom row e.g. row 5 in example.
Comments
Post a Comment