I am trying to match two columns on two separate worksheets in the same workbook
I\'m am trying to match column A in both sheets
SheetA = FindReplace SheetB = T
How about this modification? Please think of this as one of several solutions.
if (b != res.length - 1) res.push([""]);
is used.
function MatchColumns(){
// gets spreadsheet A and the range of data
var sheetA =SpreadsheetApp.getActiveSpreadsheet().getSheetByName("FindReplace");
var dataA = sheetA.getRange(2, 1, sheetA.getLastRow(), 2).getValues();
// gets spreadsheet B and the range of data
var sheetB = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Test");
var dataB = sheetB.getRange(2, 1, sheetB.getLastRow(), 1).getValues();
// Added
var res = [];
for (var b in dataB) {
for (var a in dataA) {
if (dataA[a][0] == dataB[b][0]) res.push([dataA[a][1]]);
}
if (b != res.length - 1) res.push([""]);
}
sheetB.getRange(2, 2, res.length, res[0].length).setValues(res);
}
If I misunderstand your question, please tell me. I would like to modify.
The function did run after changing the >
for <