H
H
Hattori_Hanzo2020-06-16 10:33:01
Google Apps Script
Hattori_Hanzo, 2020-06-16 10:33:01

How can I force the script to be executed line by line?

Hello! I started writing a script, but I ran into such a problem, the script is executed, but it inserts a value for the entire range, how to make sure that the value is inserted not immediately into the entire range, but as it is filled (for example, A2 is not empty, which means a value is inserted into B2 , A3 is not empty, so a value is inserted into B3, and so on)?

function onEdit() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheets()[0];
if (sheet.getRange("A2:A").isBlank()===false){
var cell = sheet.getRange("B2:B");
cell.setValue("Выполнена");
}
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Boev, 2020-06-16
@Hattori_Hanzo

I don’t understand why this should be done with a script, if it’s possible with one formula, writing in B1 :
=ARRAYFORMULA(ЕСЛИ(A1:A="";"";"Выполнено"))
If you need to change the B column when A changes , and insert “ Done ” there with a non-empty value in A , then it’s something like this:

/**
 * Возникает при изменении ячейки
* @param {e} event event-объект https://developers.google.com/apps-script/guides/triggers/events?hl=ru
 * [ ProgrammerForever (c) 2020 ]
 * @return Не возвращает значений
 */
function onEdit(event) {
  var ss = event.source.getActiveSheet();//Текущий лист
  var address = event.range.getA1Notation().toUpperCase();//Адрес ячейки
  var row = event.range.getRow();      //Номер строки
  var col = event.range.getColumn();  //Номер столбца
  var newValue = event.value;            //Новое значение
  var oldValue = event.oldValue;        //Старое значение
  var userEmail = event.user.getEmail();//Пользователь(работает только при вручную назначенном триггере)
  
  //Делаем что-то
  if((col===1)&&(newValue!="")){
    ss.getRange(row,2).setValue("Выполнено");
  };
};

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question