-1

https://docs.google.com/spreadsheets/d/1g5mLRcwBb9rLaJ4qIUy1PLaBNNfuwvXwct1cBr2QVgk/edit#gid=1271563337

basicly im trying to figure out a script that would:

  • Find match in Relação!A:A to content of Config!B3
    • in my example ABEV3 it would be Relação!A3
    • that would find a correponding row 3
  • so the matching cel in Relação!L:L would be Relação!L3
  • update Relação!L3 with content of Config!D9

basic idea with part of code that i can do to try to ilustrate

function setSheetID()
{ 

  const ss = SpreadsheetApp.getActiveSpreadsheet()
  const sheet_c = ss.getSheetByName('Config');

  var ticket = ss.getRange(3,2,1,1).getValues(); // Config!B3
  var sheetID = ss.getRange(9,4,1,1).getValues(); // Config!D9

  const sheet_r = ss.getSheetByName('Relação');

  var LR = sheet_r.getLastRow(); 
  var LC = sheet_r.getLastColumn();

  var row_to_match_with_ticket = sheet_r.getRange(1,1,LR,1).getValues(); // Relação!A:A

// that part i have no idea how to get range for target where ticket would match with row_to_match_with_ticket, so i will put the result as example

  for (var i = 0; i <= 1; i++) // i dont understand that, just setting exemple from posts ive seen
  {
    if (row_to_match_with_ticket[i] == ticket ) 
    {  
      var target = sheet_r.getRange(3,12,1,1);  // Relação!L3 // im harcoding result, cos i dont fully understant what i wrote in the example 

      sheet_r.getRange(target).setValues(sheetID);
    }
  } 

};

now i will try to ilustrate with a query: (im not in USA, so ; instead of ,)

  • to find my target:

    query('Relação'!A:L; "SELECT L WHERE (A = '"&Config!B3&"') LIMIT 1";0)

  • update that cell


  • UPDATE WITH Config!D9 ( Relação!L:L WHERE Relação!A:A = Config!B3 )
  • in this case update Relação!L3 WITH VALUES OF Config!D9

searched and results where too complex to me understand and be able to try to adapt to my needs

thanks in advance

Edit: tried to simplify, to make it easier to understand as im terrible to explain aparently, but that script would run on multiple SS that i quite often replace as i improve it, so i need each sheet to update a main sheet

Edit 2: tried to provide a logical way to understant the inputs and outputs, its might be easier to see in the sheet i provided as its comented and colored, tried to describe the best possible way i could

Edit 3: added basic code to try to show what i want to do

  • Sorry but I'm having trouble understanding the question, but to simplify this, what you would want to happen is to create a function wherein you can get Sheet ID's for multiple spreadsheets, is that correct? Feel free to correct me if I'm wrong – Century Tuna Feb 09 '22 at 17:49
  • what im trying to do is, Update Relação Sheet with ID from Config Sheet, where in this case Relação!A:A = Config!B3, it would run on multiple sheets as i constantly replace as i update them, to keep Relação as an index, did i make it easier to understand? – Bruno Carvalho Feb 09 '22 at 18:36
  • I don't understand what you want either give us a complete example inputs and outputs – Cooper Feb 09 '22 at 18:37
  • basicly find in relação sheet column L where Column A, machets value and update column L,, tried to create example with query to make it easier to understand – Bruno Carvalho Feb 09 '22 at 18:48
  • updated and simplified example and post to try to make it easier to understand – Bruno Carvalho Feb 09 '22 at 19:24
  • I agree with @MiMi, I do think it might be best that you provide a screenshot of how you would want it to look like including sample inputs and outputs on your spreadsheet to clarify the behavior that you would want to achieve – Century Tuna Feb 09 '22 at 20:38
  • @DiegoSanchez i tried to describe the best i could the inputs and outputs, take a look at the sheet i provided, just keep in mind that script would be used on multiple sheets each with different Ticket Config!B3 to match Relação!A:A – Bruno Carvalho Feb 10 '22 at 00:05
  • In your question, where can I confirm the sample input situation and the sample output situation? – Tanaike Feb 10 '22 at 01:52
  • @Tanaike im not quite sure if i understand, but Config!B3 will change to From ABVE3 to VALE3, PETR4, etc values on Relação!A:A, to update column L on same row as the result of that match – Bruno Carvalho Feb 10 '22 at 02:12
  • Thank you for replying. For example, you want to retrieve the value of cell "B3" of "Config" sheet and you want to search the retrieved value from the column "A" of "Relação" sheet. When the value is found, you want to put the value of cell "D9" of "Config" sheet to the column "L" of the same row of the searched value. Is my understanding correct? – Tanaike Feb 10 '22 at 02:25
  • @Tanaike yes, you explaning sounds way better than i did, thanks for your patience – Bruno Carvalho Feb 10 '22 at 02:33
  • Thank you for replying. From your replying, I understood that my understanding is correct. So, I posted a sample script in my answer. Could you please confirm it? – Tanaike Feb 10 '22 at 03:24

1 Answers1

1

I believe your goal is as follows.

  • You want to retrieve the value of cell "B3" of "Config" sheet.
  • You want to search the retrieved value from the column "A" of "Relação" sheet.
  • When the value is found, you want to put the value of cell "D9" of "Config" sheet to the column "L" of the same row of the searched value.

In this case, how about the following sample script?

Sample script:

function myFunction() {
  const ss = SpreadsheetApp.getActiveSpreadsheet();
  const [src, dst] = ["Config", "Relação"].map(s => ss.getSheetByName(s));
  const [b3, d9] = ["B3", "D9"].map(r => src.getRange(r).getValue());
  const search = dst.getRange("A2:A" + dst.getLastRow()).createTextFinder(b3).findNext();
  if (!search) return;
  search.offset(0, 11).setValue(d9);
}
  • In this answer, the value is searched using TextFinder.

Reference:

Tanaike
  • 181,128
  • 11
  • 97
  • 165
  • thank you @Tanaike it does solve what i was proposing, now i will try to adapt to my real needs, with multiple spreadsheets, etc, as your code has exemples im not used to, i will have to research and learn by myself, which is good, if i have problems, will make another post – Bruno Carvalho Feb 10 '22 at 12:14
  • just perfect, made minnor adjustments to fit my real needs and its working perfectly, thank you very mush, i wouldnt be abe to come up with that elegant solution + learned new things – Bruno Carvalho Feb 10 '22 at 12:41
  • @Bruno Carvalho Thank you for replying. I'm glad your issue was resolved. I could correctly understand your question by your cooperation. Thank you, too. – Tanaike Feb 10 '22 at 13:16