Answer the question
In order to leave comments, you need to log in
How to validate on a specific column?
I have a google spreadsheet. It has 2 sheets. The data in the first sheet changes regularly. There is a list of sites (this is immutable data), then a person can be attached to the site, and there is a start date and a completion date (this is mutable data). The site can be worked out by different people on different dates. Therefore, there is a need to keep a kind of log book, when and by whom a certain area was taken. The second sheet should serve as a journal entry.
It is necessary to make sure that when a person is added for a certain area + the start and completion date of work is added, then this data (together with the number of the area) is transferred to the second sheet. And inserted into the last empty cell. And so on ad infinitum. Just a journal entry.
With this script, I got access to sheet 1 and 2, got the data from the active cells of sheet 1. And transferred them to sheet 2.
function addToDatabase(){
var list1 = SpreadsheetApp.getActiveSpreadsheet(); //лист откуда берем данные
var activCell = list1.getActiveSheet().getActiveCell(); //определение ячейки на которой сейчас находится курсор
var activNum = activCell.getRow(); //номер активной ячейки
var number = list1.getActiveSheet().getRange(activNum, 1).getValue(); // номер участка
var name = list1.getActiveSheet().getRange(activNum, 2).getValue(); // имя человека
var date1 = list1.getActiveSheet().getRange(activNum, 4).getValue(); // дата начала работ
var date2 = list1.getActiveSheet().getRange(activNum, 6).getValue(); // дата завершения работ
var activColumn = list1.getActiveSheet().getActiveCell().getColumn(); //номер активного столбца
var list2 = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Журнал вода данных"); //лист куда вставляем данные
var lastEmptyRow = list2.getLastRow() + 1; //разбивка куда какие данные вставлять
list2.getRange(lastEmptyRow, 1).setValue(number); // вставить номер
list2.getRange(lastEmptyRow, 2).setValue(name); // вставить имя
var lastEmptyRow = list2.getLastRow() + 1; //разбивка куда какие данные вставлять
list2.getRange(lastEmptyRow, 1).setValue(number); // вставить номер
list2.getRange(lastEmptyRow, 2).setValue(date1); // вставить дату начала работ
list2.getRange(lastEmptyRow, 3).setValue(date2); // вставить дату завершения работ
}
Answer the question
In order to leave comments, you need to log in
If without code explanations, then
function onEdit() {
run2();
}
function run2() {
/* Remove dash */
var sheet = SpreadsheetApp.getActiveSheet();
if (sheet.getName() === 'Журнал вода данных') return;
var archive = SpreadsheetApp.getActive().getSheetByName('Журнал вода данных');
var action = function(values, i, i2) {
var data = values.slice(i, i + i2);
archive
.getRange(archive.getLastRow() + 1, 1, data.length, data[0].length)
.setValues(data);
};
var condition = function(values, i) {
var row = values[i];
return (
i > 0 && row[0] !== '' && row[1] !== '' && row[3] !== '' && row[5] !== ''
);
};
deleteRowsByConditional_(sheet, condition, action);
}
function deleteRowsByConditional_(sheet, condition, action) {
sheet
.getDataRange()
.getValues()
.forEach(
function(_, i, arr) {
var j = arr.length - i - 1;
if (this.condition.apply(null, [arr, j])) {
this.isContinue++;
if (j > 0) return;
}
if (this.isContinue > 0) {
var prevPos = j + 1; // It's reversed
if (action) action(arr, prevPos, this.isContinue);
this.sheet.deleteRows(prevPos + 1, this.isContinue);
this.isContinue = 0;
return;
}
return;
},
{ sheet: sheet, condition: condition, isContinue: 0 }
);
}
run2()
to the menu. Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question