Answer the question
In order to leave comments, you need to log in
How to finalize the script for the correct filling of the sheet in Google App Script?
It is necessary to transfer the data from one sheet to another pre-sorted. Feed the following script:
function format() {
var sourseList = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Исходные данные");
var bdList = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("БД");
var lr1 = sourseList.getLastRow();
var lr2 = bdList.getLastRow();
for(var i = 4;i<=lr1;i++){
var colB = sourseList.getRange(i, 3).getValue();
var num = sourseList.getRange(i, 2).getValue();
var balance = sourseList.getRange(i, 6).getValue();
if(colB === "0шт."){
continue;
}
bdList.getRange(i, 1).setValue(num);
bdList.getRange(i, 2).setValue(balance);
}
}
Answer the question
In order to leave comments, you need to log in
Something like this:
(the code was not tested, there may be typos, but the logic is like this)
function format() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
const sourseList = ss.getSheetByName("Исходные данные");
const bdList = ss.getSheetByName("БД");
const values = sourseList.getDataRange()
.getValues()
.filter(item => item[4] === "0шт.")
.map(item => [item[3], item[7]]);
bdList.getRange(bdList.getLastRow() + 1, 1, values.length, 2).setValues(values);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question