Answer the question
In order to leave comments, you need to log in
How to write a script for multiple columns?
At me it turned out to register a script on one column. there he is:
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var idCol = e.range.getColumn();
var idRow = e.range.getRow();
if ( idCol == 2 && sheet.getName() =='Лист1' ) {
var Value = e.range.offset(1, +5).getValues();
if ( Value == "" ) {
var vartoday = getDate();
sheet.getRange(idRow, 6).setValue( vartoday );
}
}
}
// Returns YYYYMMDD-formatted date.
function getDate() {
var today = new Date();
today.setDate(today.getDate());
//return Utilities.formatDate(today, 'PST', 'yyyy.MM.dd');
return Utilities.formatDate(today, 'GMT+03:00', 'yyyy.MM.dd');
}
Answer the question
In order to leave comments, you need to log in
I didn’t quite understand what needs to be done on the issue, but try this code - there are options for columns (1.10, etc.) and options for their corresponding columns (2.13, etc.)
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var idCol = e.range.getColumn();
var idRow = e.range.getRow();
const colsSource = [1,10];// Столбцы исходные
const colsDestination = [2,13];// Столбцы назначения
if (sheet.getName() == 'Лист1' && (colsSource.indexOf(idCol)!=-1)) { //Лист1 и idCol есть в colsSource
var Value = e.range.offset(1, +5).getValues();
if (Value == "") {
var vartoday = getDate();
const destinationCol = colsDestination[colsSource.indexOf(idCol)];
sheet.getRange(idRow, destinationCol).setValue(vartoday);
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question