javascript
1const q297640 = () => {
2 const targetSheetName = "マスター用シート";
3 const sourceSheetName = "記入用シート";
4 const keyColA1InTarget = "A"; // マスター用シートで、個人番号が何列か
5 const keyColA1InSource = "A"; // 記入用シートで、個人番号が何列か
6 const valueColA1InTarget = "B"; // マスター用シートで、注文番号が何列か
7 const valueColA1InSource = "B"; // 記入用シートで、注文番号が何列か
8
9 const keyColInTarget = alphaToPos(keyColA1InTarget);
10 const keyColInSource = alphaToPos(keyColA1InSource);
11 const valueColInTarget = alphaToPos(valueColA1InTarget);
12 const valueColInSource = alphaToPos(valueColA1InSource);
13
14 const book = SpreadsheetApp.getActive();
15 const dictionary = new Map(book.getSheetByName(sourceSheetName).getDataRange().getValues().map(r=> [r[keyColInSource],r[valueColInSource]]));
16 const targetSheet = book.getSheetByName(targetSheetName);
17 const data = targetSheet.getDataRange().getValues().map(r=>r.map((c,i)=> i === valueColInTarget && dictionary.get(r[keyColInTarget]) ? dictionary.get(r[keyColInTarget]) : c));
18 targetSheetName.getRange(1,1,data.length,data[0].length).setValues(data);
19}
20const alphaToPos = (c) => "ABCDEFGHIJKLMNOPQRSTUVWXYZ".indexOf(c);