Script works really well but I have 12 columns and this script only works on A and B.
function onEditTwoWay(e) {
var ss = SpreadsheetApp;
var sheet = ss.getActiveSpreadsheet();
var sheet1 = sheet.getSheetByName("Dep1");
var sheet2 = sheet.getSheetByName("Dep2");
var cell = sheet.getActiveCell();
var value = cell.getValue();
var currentRow = cell.getRow();
var currentColumn = cell.getColumn();
var activeWorksheet = ["Dep1","Dep2"];
var columnEdit = [1,2,12];
if(activeWorksheet.indexOf(ss.getActiveSheet().getName()) > -1 &&
columnEdit.indexOf(currentColumn) > -1 && currentRow > 1) {
sheet1.getRange(currentRow, currentColumn).setValue(value);
sheet2.getRange(currentRow, currentColumn).setValue(value);
};
};
CodePudding user response:
All columns need to be entered in columnEdit
so changed from
columnEdit = [1,2,12]
to columnEdit = [1,2,3,4,5,6,7,8,9,10,11,12]
CodePudding user response:
Try this:
function onEdit(e) {
const sh = e.range.getSheet();
var shts = ["Dep1", "Dep2"];
var cols = [1, 2, 12];
if (~shts.indexOf(sh.getName()) && ~cols.indexOf(e.range.columnStart) && e.range.rowStart > 1) {
shts.forEach(name => {
e.source.getSheetByName(name).getRange(e.range.rowStart, e.range.columnStart).setValue(e.value);
});
}
}