merge values in column in a row with the quotes separator “|”, based on a comparison with the values of...











up vote
1
down vote

favorite
1












as the title suggests I'm trying to find a way to treat some data in a spreadsheet to google app.
I think the best way is to directly set an example and thank you in advance for your support as always.



simply:



sheet1 (colA, colB)

sheet2 (colA', colB')

sheet1
colA colB
1 xxx 40
2 xxx 42
3 yyy 42
4 yyy 44
. ... etc.


sheet2

colA' colB'

1 xxx 40 | 42

2 yyy 42 | 44

3 ... .. | .. (etc.)


I would be grateful for a hint of code to google app script.
thanks





EDIT (in progress)



hi,



I hope that by sharing the file answer your questions.



the sheet already exist, the code is written in part and I would need help on this.



there is no duplication in ColumnB for article xxx or yyy or zzz etc. ..



in sheet "sheet_demo" indicates that the script should be.



Spreadsheeet demo





function merge_col() {

var sheet = SpreadsheetApp.openById("0AiuqXkUqDMgzdFM5aVNxeEhPbWFmbGhybl9TVkt4ZWc");
var ss_sorg = sheet.getSheetByName('sheet1');
var ss_dest = sheet.getSheetByName('sheet2');

var sorg_data = ss_sorg.getRange("A2:C").getValues();
var dest_data = ss_dest.getRange("A2:C").getValues();
var dest_Cod = ;
var dest_Des = ;
var temp_Cod, temp_Des;

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

temp_Cod = null;
temp_Des = null;

for (var j = 1; j < sorg_data.length; j++) {

if (sorg_data[i][0] == sorg_data[j][0].toString().match(sorg_data[i][0]) && sorg_data[i][0] != "") {

temp_Cod = sorg_data[i][1];
temp_Des = sorg_data[i][2];

break;
}
}

dest_Cod.push([temp_Cod]);
dest_Cod.join('|');
dest_Des.push([temp_Des]);
dest_Des.join('|');
}
if (dest_Cod.length > 0 || dest_Des.lenght > 0) {
ss_dest.getRange(2, 2, dest_Cod.length, 1).setValues(dest_Cod); Logger.log(dest_Cod)
ss_dest.getRange(2, 3, dest_Des.length, 1).setValues(dest_Des); Logger.log(dest_Des)
}
}


EDIT (FINAL)
TKS Serge!



function merge_col() {
var ss = SpreadsheetApp.getActive().getSheetByName('sheet1');
var data = ss.getDataRange().getValues();
var header = data.shift();
var col1 = data[1][0];
var col2 = '';
var col3 = '';
var dataSheet2 = [header];
for(var i=0 ; i<data.length ; i++){
Logger.log(data[i][0]+' - '+col1+' - '+data[i][2])
if(col1==data[i][0]){
col1 = data[i][0];
col2+=data[i][1]+' | ';
col3+=data[i][2]+' | ';
}else{
dataSheet2.push([col1,col2,col3]);
var col1 = data[i][0];
col2 = data[i][1]+' | ';
col3 = data[i][2]+' | ';
}
}
dataSheet2.push([col1,col2,col3]);
Logger.log(dataSheet2);
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
sheet2.clear();
sheet2.getRange(1, 1, dataSheet2.length, dataSheet2[0].length).setValues(dataSheet2);
}









share|improve this question
























  • Just a few questions: have you tried some code? Are there more than 2 occurrence of the same item xxx or yyy? Does sheet already exist?
    – Serge insas
    Feb 10 '14 at 16:42










  • Thanks, now it's perfectly clear :-)
    – Serge insas
    Feb 11 '14 at 6:35















up vote
1
down vote

favorite
1












as the title suggests I'm trying to find a way to treat some data in a spreadsheet to google app.
I think the best way is to directly set an example and thank you in advance for your support as always.



simply:



sheet1 (colA, colB)

sheet2 (colA', colB')

sheet1
colA colB
1 xxx 40
2 xxx 42
3 yyy 42
4 yyy 44
. ... etc.


sheet2

colA' colB'

1 xxx 40 | 42

2 yyy 42 | 44

3 ... .. | .. (etc.)


I would be grateful for a hint of code to google app script.
thanks





EDIT (in progress)



hi,



I hope that by sharing the file answer your questions.



the sheet already exist, the code is written in part and I would need help on this.



there is no duplication in ColumnB for article xxx or yyy or zzz etc. ..



in sheet "sheet_demo" indicates that the script should be.



Spreadsheeet demo





function merge_col() {

var sheet = SpreadsheetApp.openById("0AiuqXkUqDMgzdFM5aVNxeEhPbWFmbGhybl9TVkt4ZWc");
var ss_sorg = sheet.getSheetByName('sheet1');
var ss_dest = sheet.getSheetByName('sheet2');

var sorg_data = ss_sorg.getRange("A2:C").getValues();
var dest_data = ss_dest.getRange("A2:C").getValues();
var dest_Cod = ;
var dest_Des = ;
var temp_Cod, temp_Des;

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

temp_Cod = null;
temp_Des = null;

for (var j = 1; j < sorg_data.length; j++) {

if (sorg_data[i][0] == sorg_data[j][0].toString().match(sorg_data[i][0]) && sorg_data[i][0] != "") {

temp_Cod = sorg_data[i][1];
temp_Des = sorg_data[i][2];

break;
}
}

dest_Cod.push([temp_Cod]);
dest_Cod.join('|');
dest_Des.push([temp_Des]);
dest_Des.join('|');
}
if (dest_Cod.length > 0 || dest_Des.lenght > 0) {
ss_dest.getRange(2, 2, dest_Cod.length, 1).setValues(dest_Cod); Logger.log(dest_Cod)
ss_dest.getRange(2, 3, dest_Des.length, 1).setValues(dest_Des); Logger.log(dest_Des)
}
}


EDIT (FINAL)
TKS Serge!



function merge_col() {
var ss = SpreadsheetApp.getActive().getSheetByName('sheet1');
var data = ss.getDataRange().getValues();
var header = data.shift();
var col1 = data[1][0];
var col2 = '';
var col3 = '';
var dataSheet2 = [header];
for(var i=0 ; i<data.length ; i++){
Logger.log(data[i][0]+' - '+col1+' - '+data[i][2])
if(col1==data[i][0]){
col1 = data[i][0];
col2+=data[i][1]+' | ';
col3+=data[i][2]+' | ';
}else{
dataSheet2.push([col1,col2,col3]);
var col1 = data[i][0];
col2 = data[i][1]+' | ';
col3 = data[i][2]+' | ';
}
}
dataSheet2.push([col1,col2,col3]);
Logger.log(dataSheet2);
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
sheet2.clear();
sheet2.getRange(1, 1, dataSheet2.length, dataSheet2[0].length).setValues(dataSheet2);
}









share|improve this question
























  • Just a few questions: have you tried some code? Are there more than 2 occurrence of the same item xxx or yyy? Does sheet already exist?
    – Serge insas
    Feb 10 '14 at 16:42










  • Thanks, now it's perfectly clear :-)
    – Serge insas
    Feb 11 '14 at 6:35













up vote
1
down vote

favorite
1









up vote
1
down vote

favorite
1






1





as the title suggests I'm trying to find a way to treat some data in a spreadsheet to google app.
I think the best way is to directly set an example and thank you in advance for your support as always.



simply:



sheet1 (colA, colB)

sheet2 (colA', colB')

sheet1
colA colB
1 xxx 40
2 xxx 42
3 yyy 42
4 yyy 44
. ... etc.


sheet2

colA' colB'

1 xxx 40 | 42

2 yyy 42 | 44

3 ... .. | .. (etc.)


I would be grateful for a hint of code to google app script.
thanks





EDIT (in progress)



hi,



I hope that by sharing the file answer your questions.



the sheet already exist, the code is written in part and I would need help on this.



there is no duplication in ColumnB for article xxx or yyy or zzz etc. ..



in sheet "sheet_demo" indicates that the script should be.



Spreadsheeet demo





function merge_col() {

var sheet = SpreadsheetApp.openById("0AiuqXkUqDMgzdFM5aVNxeEhPbWFmbGhybl9TVkt4ZWc");
var ss_sorg = sheet.getSheetByName('sheet1');
var ss_dest = sheet.getSheetByName('sheet2');

var sorg_data = ss_sorg.getRange("A2:C").getValues();
var dest_data = ss_dest.getRange("A2:C").getValues();
var dest_Cod = ;
var dest_Des = ;
var temp_Cod, temp_Des;

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

temp_Cod = null;
temp_Des = null;

for (var j = 1; j < sorg_data.length; j++) {

if (sorg_data[i][0] == sorg_data[j][0].toString().match(sorg_data[i][0]) && sorg_data[i][0] != "") {

temp_Cod = sorg_data[i][1];
temp_Des = sorg_data[i][2];

break;
}
}

dest_Cod.push([temp_Cod]);
dest_Cod.join('|');
dest_Des.push([temp_Des]);
dest_Des.join('|');
}
if (dest_Cod.length > 0 || dest_Des.lenght > 0) {
ss_dest.getRange(2, 2, dest_Cod.length, 1).setValues(dest_Cod); Logger.log(dest_Cod)
ss_dest.getRange(2, 3, dest_Des.length, 1).setValues(dest_Des); Logger.log(dest_Des)
}
}


EDIT (FINAL)
TKS Serge!



function merge_col() {
var ss = SpreadsheetApp.getActive().getSheetByName('sheet1');
var data = ss.getDataRange().getValues();
var header = data.shift();
var col1 = data[1][0];
var col2 = '';
var col3 = '';
var dataSheet2 = [header];
for(var i=0 ; i<data.length ; i++){
Logger.log(data[i][0]+' - '+col1+' - '+data[i][2])
if(col1==data[i][0]){
col1 = data[i][0];
col2+=data[i][1]+' | ';
col3+=data[i][2]+' | ';
}else{
dataSheet2.push([col1,col2,col3]);
var col1 = data[i][0];
col2 = data[i][1]+' | ';
col3 = data[i][2]+' | ';
}
}
dataSheet2.push([col1,col2,col3]);
Logger.log(dataSheet2);
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
sheet2.clear();
sheet2.getRange(1, 1, dataSheet2.length, dataSheet2[0].length).setValues(dataSheet2);
}









share|improve this question















as the title suggests I'm trying to find a way to treat some data in a spreadsheet to google app.
I think the best way is to directly set an example and thank you in advance for your support as always.



simply:



sheet1 (colA, colB)

sheet2 (colA', colB')

sheet1
colA colB
1 xxx 40
2 xxx 42
3 yyy 42
4 yyy 44
. ... etc.


sheet2

colA' colB'

1 xxx 40 | 42

2 yyy 42 | 44

3 ... .. | .. (etc.)


I would be grateful for a hint of code to google app script.
thanks





EDIT (in progress)



hi,



I hope that by sharing the file answer your questions.



the sheet already exist, the code is written in part and I would need help on this.



there is no duplication in ColumnB for article xxx or yyy or zzz etc. ..



in sheet "sheet_demo" indicates that the script should be.



Spreadsheeet demo





function merge_col() {

var sheet = SpreadsheetApp.openById("0AiuqXkUqDMgzdFM5aVNxeEhPbWFmbGhybl9TVkt4ZWc");
var ss_sorg = sheet.getSheetByName('sheet1');
var ss_dest = sheet.getSheetByName('sheet2');

var sorg_data = ss_sorg.getRange("A2:C").getValues();
var dest_data = ss_dest.getRange("A2:C").getValues();
var dest_Cod = ;
var dest_Des = ;
var temp_Cod, temp_Des;

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

temp_Cod = null;
temp_Des = null;

for (var j = 1; j < sorg_data.length; j++) {

if (sorg_data[i][0] == sorg_data[j][0].toString().match(sorg_data[i][0]) && sorg_data[i][0] != "") {

temp_Cod = sorg_data[i][1];
temp_Des = sorg_data[i][2];

break;
}
}

dest_Cod.push([temp_Cod]);
dest_Cod.join('|');
dest_Des.push([temp_Des]);
dest_Des.join('|');
}
if (dest_Cod.length > 0 || dest_Des.lenght > 0) {
ss_dest.getRange(2, 2, dest_Cod.length, 1).setValues(dest_Cod); Logger.log(dest_Cod)
ss_dest.getRange(2, 3, dest_Des.length, 1).setValues(dest_Des); Logger.log(dest_Des)
}
}


EDIT (FINAL)
TKS Serge!



function merge_col() {
var ss = SpreadsheetApp.getActive().getSheetByName('sheet1');
var data = ss.getDataRange().getValues();
var header = data.shift();
var col1 = data[1][0];
var col2 = '';
var col3 = '';
var dataSheet2 = [header];
for(var i=0 ; i<data.length ; i++){
Logger.log(data[i][0]+' - '+col1+' - '+data[i][2])
if(col1==data[i][0]){
col1 = data[i][0];
col2+=data[i][1]+' | ';
col3+=data[i][2]+' | ';
}else{
dataSheet2.push([col1,col2,col3]);
var col1 = data[i][0];
col2 = data[i][1]+' | ';
col3 = data[i][2]+' | ';
}
}
dataSheet2.push([col1,col2,col3]);
Logger.log(dataSheet2);
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
sheet2.clear();
sheet2.getRange(1, 1, dataSheet2.length, dataSheet2[0].length).setValues(dataSheet2);
}






google-apps-script google-sheets






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 11 at 6:20









Cœur

17k9102140




17k9102140










asked Feb 10 '14 at 15:42









gigisan76

83




83












  • Just a few questions: have you tried some code? Are there more than 2 occurrence of the same item xxx or yyy? Does sheet already exist?
    – Serge insas
    Feb 10 '14 at 16:42










  • Thanks, now it's perfectly clear :-)
    – Serge insas
    Feb 11 '14 at 6:35


















  • Just a few questions: have you tried some code? Are there more than 2 occurrence of the same item xxx or yyy? Does sheet already exist?
    – Serge insas
    Feb 10 '14 at 16:42










  • Thanks, now it's perfectly clear :-)
    – Serge insas
    Feb 11 '14 at 6:35
















Just a few questions: have you tried some code? Are there more than 2 occurrence of the same item xxx or yyy? Does sheet already exist?
– Serge insas
Feb 10 '14 at 16:42




Just a few questions: have you tried some code? Are there more than 2 occurrence of the same item xxx or yyy? Does sheet already exist?
– Serge insas
Feb 10 '14 at 16:42












Thanks, now it's perfectly clear :-)
– Serge insas
Feb 11 '14 at 6:35




Thanks, now it's perfectly clear :-)
– Serge insas
Feb 11 '14 at 6:35












2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










Here is a code that does exactly what you expected using a simple loop and a comparison.



function merge_col() {
var ss = SpreadsheetApp.getActive().getSheetByName('sheet1');
var data = ss.getDataRange().getValues();
var header = data.shift();
var col1 = data[1][0];
var col2 = '';
var col3 = '';
var dataSheet2 = [header];
for(var i=0 ; i<data.length ; i++){
Logger.log(data[i][0]+' - '+col1+' - '+data[i][2])
if(col1==data[i][0]){
col1 = data[i][0];
col2+=data[i][1]+' | ';
col3+=data[i][2]+' | ';
}else{
dataSheet2.push([col1,col2,col3]);
var col1 = data[i][0];
col2 = data[i][1]+' | ';
col3 = data[i][2]+' | ';
}
}
dataSheet2.push([col1,col2,col3]);
Logger.log(dataSheet2);
var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
sheet2.clear();
sheet2.getRange(1, 1, dataSheet2.length, dataSheet2[0].length).setValues(dataSheet2);
}





share|improve this answer





















  • excellent, it works fine. tks!
    – gigisan76
    Feb 11 '14 at 10:35










  • you're welcome, don't forget to mark as answered :-)
    – Serge insas
    Feb 11 '14 at 10:38


















up vote
0
down vote













have a look at this post, he want to do almost the same. Modifying 2 lines of the code and it's done:



function myFunction() {
var objList={};
var ss = SpreadsheetApp.getActive().getActiveSheet();
var data = ss.getDataRange().getValues();
for(var i in data){
// for(var j in data[i]){
if(typeof objList[data[i][0]]=="undefined"){
objList[data[i][0]]=; // new array
objList[data[i][0]].push(data[i][1]); // push the value of the second column
}
else{
objList[data[i][0]].push(data[i][1]);
}
//}
}
var objTable=;
for(var k in objList){
objTable.push([k,objList[k]]);
}
Logger.log(objTable);
ss.clear();
ss.getRange(1, 1, objTable.length, objTable[0].length).setValues(objTable);
}





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21681523%2fmerge-values-in-column-in-a-row-with-the-quotes-separator-based-on-a-compar%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Here is a code that does exactly what you expected using a simple loop and a comparison.



    function merge_col() {
    var ss = SpreadsheetApp.getActive().getSheetByName('sheet1');
    var data = ss.getDataRange().getValues();
    var header = data.shift();
    var col1 = data[1][0];
    var col2 = '';
    var col3 = '';
    var dataSheet2 = [header];
    for(var i=0 ; i<data.length ; i++){
    Logger.log(data[i][0]+' - '+col1+' - '+data[i][2])
    if(col1==data[i][0]){
    col1 = data[i][0];
    col2+=data[i][1]+' | ';
    col3+=data[i][2]+' | ';
    }else{
    dataSheet2.push([col1,col2,col3]);
    var col1 = data[i][0];
    col2 = data[i][1]+' | ';
    col3 = data[i][2]+' | ';
    }
    }
    dataSheet2.push([col1,col2,col3]);
    Logger.log(dataSheet2);
    var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
    sheet2.clear();
    sheet2.getRange(1, 1, dataSheet2.length, dataSheet2[0].length).setValues(dataSheet2);
    }





    share|improve this answer





















    • excellent, it works fine. tks!
      – gigisan76
      Feb 11 '14 at 10:35










    • you're welcome, don't forget to mark as answered :-)
      – Serge insas
      Feb 11 '14 at 10:38















    up vote
    0
    down vote



    accepted










    Here is a code that does exactly what you expected using a simple loop and a comparison.



    function merge_col() {
    var ss = SpreadsheetApp.getActive().getSheetByName('sheet1');
    var data = ss.getDataRange().getValues();
    var header = data.shift();
    var col1 = data[1][0];
    var col2 = '';
    var col3 = '';
    var dataSheet2 = [header];
    for(var i=0 ; i<data.length ; i++){
    Logger.log(data[i][0]+' - '+col1+' - '+data[i][2])
    if(col1==data[i][0]){
    col1 = data[i][0];
    col2+=data[i][1]+' | ';
    col3+=data[i][2]+' | ';
    }else{
    dataSheet2.push([col1,col2,col3]);
    var col1 = data[i][0];
    col2 = data[i][1]+' | ';
    col3 = data[i][2]+' | ';
    }
    }
    dataSheet2.push([col1,col2,col3]);
    Logger.log(dataSheet2);
    var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
    sheet2.clear();
    sheet2.getRange(1, 1, dataSheet2.length, dataSheet2[0].length).setValues(dataSheet2);
    }





    share|improve this answer





















    • excellent, it works fine. tks!
      – gigisan76
      Feb 11 '14 at 10:35










    • you're welcome, don't forget to mark as answered :-)
      – Serge insas
      Feb 11 '14 at 10:38













    up vote
    0
    down vote



    accepted







    up vote
    0
    down vote



    accepted






    Here is a code that does exactly what you expected using a simple loop and a comparison.



    function merge_col() {
    var ss = SpreadsheetApp.getActive().getSheetByName('sheet1');
    var data = ss.getDataRange().getValues();
    var header = data.shift();
    var col1 = data[1][0];
    var col2 = '';
    var col3 = '';
    var dataSheet2 = [header];
    for(var i=0 ; i<data.length ; i++){
    Logger.log(data[i][0]+' - '+col1+' - '+data[i][2])
    if(col1==data[i][0]){
    col1 = data[i][0];
    col2+=data[i][1]+' | ';
    col3+=data[i][2]+' | ';
    }else{
    dataSheet2.push([col1,col2,col3]);
    var col1 = data[i][0];
    col2 = data[i][1]+' | ';
    col3 = data[i][2]+' | ';
    }
    }
    dataSheet2.push([col1,col2,col3]);
    Logger.log(dataSheet2);
    var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
    sheet2.clear();
    sheet2.getRange(1, 1, dataSheet2.length, dataSheet2[0].length).setValues(dataSheet2);
    }





    share|improve this answer












    Here is a code that does exactly what you expected using a simple loop and a comparison.



    function merge_col() {
    var ss = SpreadsheetApp.getActive().getSheetByName('sheet1');
    var data = ss.getDataRange().getValues();
    var header = data.shift();
    var col1 = data[1][0];
    var col2 = '';
    var col3 = '';
    var dataSheet2 = [header];
    for(var i=0 ; i<data.length ; i++){
    Logger.log(data[i][0]+' - '+col1+' - '+data[i][2])
    if(col1==data[i][0]){
    col1 = data[i][0];
    col2+=data[i][1]+' | ';
    col3+=data[i][2]+' | ';
    }else{
    dataSheet2.push([col1,col2,col3]);
    var col1 = data[i][0];
    col2 = data[i][1]+' | ';
    col3 = data[i][2]+' | ';
    }
    }
    dataSheet2.push([col1,col2,col3]);
    Logger.log(dataSheet2);
    var sheet2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('sheet2');
    sheet2.clear();
    sheet2.getRange(1, 1, dataSheet2.length, dataSheet2[0].length).setValues(dataSheet2);
    }






    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Feb 11 '14 at 9:41









    Serge insas

    34.8k45387




    34.8k45387












    • excellent, it works fine. tks!
      – gigisan76
      Feb 11 '14 at 10:35










    • you're welcome, don't forget to mark as answered :-)
      – Serge insas
      Feb 11 '14 at 10:38


















    • excellent, it works fine. tks!
      – gigisan76
      Feb 11 '14 at 10:35










    • you're welcome, don't forget to mark as answered :-)
      – Serge insas
      Feb 11 '14 at 10:38
















    excellent, it works fine. tks!
    – gigisan76
    Feb 11 '14 at 10:35




    excellent, it works fine. tks!
    – gigisan76
    Feb 11 '14 at 10:35












    you're welcome, don't forget to mark as answered :-)
    – Serge insas
    Feb 11 '14 at 10:38




    you're welcome, don't forget to mark as answered :-)
    – Serge insas
    Feb 11 '14 at 10:38












    up vote
    0
    down vote













    have a look at this post, he want to do almost the same. Modifying 2 lines of the code and it's done:



    function myFunction() {
    var objList={};
    var ss = SpreadsheetApp.getActive().getActiveSheet();
    var data = ss.getDataRange().getValues();
    for(var i in data){
    // for(var j in data[i]){
    if(typeof objList[data[i][0]]=="undefined"){
    objList[data[i][0]]=; // new array
    objList[data[i][0]].push(data[i][1]); // push the value of the second column
    }
    else{
    objList[data[i][0]].push(data[i][1]);
    }
    //}
    }
    var objTable=;
    for(var k in objList){
    objTable.push([k,objList[k]]);
    }
    Logger.log(objTable);
    ss.clear();
    ss.getRange(1, 1, objTable.length, objTable[0].length).setValues(objTable);
    }





    share|improve this answer



























      up vote
      0
      down vote













      have a look at this post, he want to do almost the same. Modifying 2 lines of the code and it's done:



      function myFunction() {
      var objList={};
      var ss = SpreadsheetApp.getActive().getActiveSheet();
      var data = ss.getDataRange().getValues();
      for(var i in data){
      // for(var j in data[i]){
      if(typeof objList[data[i][0]]=="undefined"){
      objList[data[i][0]]=; // new array
      objList[data[i][0]].push(data[i][1]); // push the value of the second column
      }
      else{
      objList[data[i][0]].push(data[i][1]);
      }
      //}
      }
      var objTable=;
      for(var k in objList){
      objTable.push([k,objList[k]]);
      }
      Logger.log(objTable);
      ss.clear();
      ss.getRange(1, 1, objTable.length, objTable[0].length).setValues(objTable);
      }





      share|improve this answer

























        up vote
        0
        down vote










        up vote
        0
        down vote









        have a look at this post, he want to do almost the same. Modifying 2 lines of the code and it's done:



        function myFunction() {
        var objList={};
        var ss = SpreadsheetApp.getActive().getActiveSheet();
        var data = ss.getDataRange().getValues();
        for(var i in data){
        // for(var j in data[i]){
        if(typeof objList[data[i][0]]=="undefined"){
        objList[data[i][0]]=; // new array
        objList[data[i][0]].push(data[i][1]); // push the value of the second column
        }
        else{
        objList[data[i][0]].push(data[i][1]);
        }
        //}
        }
        var objTable=;
        for(var k in objList){
        objTable.push([k,objList[k]]);
        }
        Logger.log(objTable);
        ss.clear();
        ss.getRange(1, 1, objTable.length, objTable[0].length).setValues(objTable);
        }





        share|improve this answer














        have a look at this post, he want to do almost the same. Modifying 2 lines of the code and it's done:



        function myFunction() {
        var objList={};
        var ss = SpreadsheetApp.getActive().getActiveSheet();
        var data = ss.getDataRange().getValues();
        for(var i in data){
        // for(var j in data[i]){
        if(typeof objList[data[i][0]]=="undefined"){
        objList[data[i][0]]=; // new array
        objList[data[i][0]].push(data[i][1]); // push the value of the second column
        }
        else{
        objList[data[i][0]].push(data[i][1]);
        }
        //}
        }
        var objTable=;
        for(var k in objList){
        objTable.push([k,objList[k]]);
        }
        Logger.log(objTable);
        ss.clear();
        ss.getRange(1, 1, objTable.length, objTable[0].length).setValues(objTable);
        }






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited May 23 '17 at 11:44









        Community

        11




        11










        answered Feb 11 '14 at 6:50









        Harold

        2,82711423




        2,82711423






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f21681523%2fmerge-values-in-column-in-a-row-with-the-quotes-separator-based-on-a-compar%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python