Answer the question
In order to leave comments, you need to log in
How to write changed line in Google Sheets?
I want that when you change a line in the table, it will be written to another sheet with all the data of this line
. Found the Script, but it only writes the changed line
function onEdit(event){
if ((event.source.getActiveRange().getA1Notation()=="C2")||(event.source.getActiveRange().getA1Notation()=="E2")&&(event.source.getActiveRange().getA1Notation()=="G2")&&(event.source.getActiveSheet().getName()=="Тест")){
var arc=SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Лог");
arc.getRange(arc.getLastRow()+2,2,2,2).setValues();
console.log(event.source.getActiveRange().getValue());
};
};
Answer the question
In order to leave comments, you need to log in
I would write like this.
Now, as in your code, it will only record if there were changes in cell C2 or E2 or G2.
function onEdit(event) {
const sheet = event.source
const activeRangeA1Notation = sheet.getActiveRange().getA1Notation()
const idRow = event.range.getRow();
const maxCol = sheet.getLastColumn()
if (activeRangeA1Notation == "C2" || activeRangeA1Notation == "E2" || activeRangeA1Notation == "G2" && sheet.getActiveSheet().getName() == "Тест") {
let getValues = sheet.getActiveSheet().getRange(idRow, 1, 1, maxCol).getValues()
const arc = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Лог");
const lastRow = arc.getLastRow()
arc.getRange(lastRow + 1, 1, 1, getValues[0].length).setValues(getValues);
};
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question