I am trying to compare two columns and find a match then return value from adjacent cell. I searched for answers on google but I could not find an answer that I could use. Most everything I saw did not use script but a sheets formula. the few I functions I did see didn't fit either.
function findDuplicate() {
var sheet1 = SpreadsheetApp.getSheetByName('Working');
var s1 = sheet1.getRange('A:A').getValues();
var sheet2 = SpreadsheetApp.getSheetByName('Match');
var s2 = sheet1.getRange('A:A').getValues();
var mv = s1 === s2;
var matchedValue = mv.getvalue();
return matchedValue.offset(0, 1);
}
I am unsure how to fully do this. I understand my code is incomplete but I started down the path the best I know how. And for ease of time, yes I need this to be done in Apps Script as it will be part of another bunch of code.
example sheet link below https://docs.google.com/spreadsheets/d/1OKFoS17le-Y5SAOecoLE4EJxiKqKVjRLRHtMzwHNwxM/edit?usp=sharing
function findDuplicate() {
const ss = SpreadsheetApp.getActive();
const sh1 = ss.getSheetByName('Working');
const vs1 = sh1.getRange('H1:H' + sh1.getLastRow()).getValues();
const sh2 = ss.getSheetByName('Match');
const vs2 = sh1.getRange('A1:B' + sh2.getLastRow()).getValues();
let o = [];
vs1.forEach((r,i) => {
if(r[0] == vs2[i][0]) {
o.push(vs2[i][1]);
}
});
Logger.log(JSON.stringify(o));
return o;
}