-2
2022.04.07
以下のスクリプトを持っていますが、これをもっと効率的にする方法があれば教えてください。動作は素晴らしいのですが、必要なことを行うのに少し時間がかかります。主に、clearContent()を1つに凝縮する方法はありますか?また、より効率的にするための他の方法もあれば教えてください。ありがとうございます。
function onEdit(){
var tabLists = "Master";
var tabValidation = "Planning";
var ss = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var datass = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(tabLists);
var activeCell = ss.getActiveCell();
if(activeCell.getColumn() == 3 && activeCell.getRow() > 4 && ss.getSheetName() == tabValidation){
activeCell.offset(0,1).clearContent().clearDataValidations();
activeCell.offset(0,4).clearContent();
activeCell.offset(0,5).clearContent();
activeCell.offset(0,6).clearContent();
activeCell.offset(0,9).clearContent();
activeCell.offset(0,12).clearContent();
activeCell.offset(0,16).clearContent();
activeCell.offset(0,21).clearContent();
var makes = datass.getRange(3, 1, 1, datass.getLastColumn()).getValues();
var makeIndex = makes[0].indexOf(activeCell.getValue()) + 1;
if(makeIndex != 0){
var validationRange = datass.getRange(4, makeIndex, datass.getLastRow());
var validationRule = SpreadsheetApp.newDataValidation().requireValueInRange(validationRange).build();
activeCell.offset(0, 1).setDataValidation(validationRule);
}
}
}