Reputation: 3
Hello Good day!
I am new here, so I apologize if I do something wrong. I need help making a google sheet document script.
Basically what I need is when I click the "My tools>copy to location B" in the menu bar, I want to find current sheet's(Sheet1) cell value in location B(K:K)&(L:L). search it in location A(A:A)&(B:B) of all sheets and copy the train route and location A in reversed(notice the tabs in the pictures). Thank you very much in advance.
Best Regards,
Tim
Upvotes: 0
Views: 373
Reputation: 64040
This will undoubtedly need some testing and debugging
function findAndCopyInReverseSomewhat()
{
var ss=SpreadsheetApp.getActive();
var sh=ss.getSheetByName('Sheet1');
var rg=sh.getDataRange();
var vA=rg.getValues();
var allSheets=ss.getSheets();
for(var i=1;i<vA.length;i++)
{
for(var j=0;j<allSheets.length;j++)
{
if(allSheets[j].getName()!='Sheet1')
{
var sA=allSheets[j].getDataRange().getValues();
for(var k=1;k<sA.length;k++)
{
if(vA[i][10]==sA[k][0] && vA[i][11]==sA[k][1])
{
allSheets[j].getRange(k+1, 3, 1, 10).setValues([[vA[i][9],vA[i][8],vA[i][7],vA[i][6],vA[i][5],vA[i][4],vA[i][3],vA[i][2],vA[i][10],vA[i][11]]]);
}
}
}
}
}
}
Upvotes: 0