[Solved] Script setValue based on the values of column based on value of other column matching reference


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:

3

solved Script setValue based on the values of column based on value of other column matching reference