Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I modified a similar script I answered recently that should do what you need. I didn't test but you can give it a try. There are some comments to explain the idea... it probably needs some debugging.</p> <p><strong>EDIT :</strong> I played around with this and debugged it a bit more ;-) so it seems to work as needed now - here is <a href="https://docs.google.com/spreadsheet/ccc?key=0AnqSFd3iikE3dFVGSDZuaFVYRGJuR3lQMktsd0l0ckE" rel="nofollow">the link to my test sheet</a></p> <pre><code>function xxx(){ /* we have an array 'keysheet' and an array datasheet , you get these with something like*/ var keysheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0].getDataRange().getValues(); // and var datasheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1].getDataRange().getValues();// if other columns, change index values in the arrays : 0=A, 1=B ... // the iteration could be like this : for(i=0;i&lt;datasheet.length;++i){ // don't miss any data for(j=0;j&lt;keysheet.length;++j){ // iterate through keysheet to find the keys for(k=1;k&lt;keysheet[0].length;++k){ // iterate in keysheet row to check every column except first one var key = keysheet[j][k] Logger.log(k+' '+key+" "+datasheet[i].toString().match(key)) if(datasheet[i].toString().match(key) == key){// check whole rows to find if key is in data var x = datasheet[i].shift(); datasheet[i].unshift(keysheet[j][0]) // if match found, replace first element in datasheet with fisrt element in keysheet break // if found break k loop maybe you should also break j loop ? } } } //loop keysheet } // loop datasheet /* now you have a modified datasheet array that can directly overwrite the old datasheet using setValues() */ var sh = SpreadsheetApp.getActiveSpreadsheet().getSheets()[1];// assuming the datasheet sheet is sheet nr2 Logger.log(datasheet) sh.getRange(1,1,datasheet.length,datasheet[0].length).setValues(datasheet); } // </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload