This seems like it should be super simple but I really cannot find a solution via Google Script. I want to compare all the cells in SKU (A) in Import to SKU (A) in Pricelist, and if there is a match then paste the matching SKU's into Sheet 3 (A).
Normally I would just do this through index match but I need to do it with Google Script.
I have tried the following and this works for checking a single cell (A81) with the whole range in Pricelist A1:A100 but I cannot make sense of it when checking a range against a range.
function checkProduct() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var lookup = ss.getRange('Import!A81').getValue();
var range = ss.getRange('Pricelist!A1:A200').getValues();
var lookupRange = [];
for (var i = 0; i < range.length; i++) {
lookupRange.push(range[i][0]);
}
var index = lookupRange.indexOf(lookup);
if (index == -1) {
}
else {
ss.getRange('Sheet3!A1').setValue('its there'); // need to paste in the matching SKU
}
}
Import Sheet
SKU | Price
s123 | 99
s124 | 98
s125 | 97
Pricelist Sheet
SKU | Price
s123 | 99
a111 | 98
a453 | 97