There is a table "Test" and "DB".

In the table "Test", Sheet "A" when executing the script, you need to move the data from cell B2 to table "DB", Sheet "B" to empty cells "B2: B" of the desired ID "A2: A" from the previous table "A2 ". (Image 1)

Image 1

And if the data is already there, do not record anything. (Image 2)

Image 2

The result of the correct operation of the script. (Image 3)

Image 3

    1 answer 1

    function myFunction() { var sheetA = SpreadsheetApp.openById('Ключ таблицы А') .getSheetByName('Имя нужного листа в таблице A'); var sheetB = SpreadsheetApp.openById('Ключ таблицы B') .getSheetByName('Имя нужного листа в таблице B'); var valueId = sheetA.getRange(2, 1).getValue(); var valueData = sheetA.getRange(2, 2).getValue(); var arrayId = sheetB.getRange("A:A").getValues(); var ln = sheetB.getLastRow(); for (var i = 0; i < ln; i++) { var cache = arrayId[i][0]; if (cache == valueId) { if (sheetB.getRange(i + 1, 2).getValue() == '') { sheetB.getRange(i + 1, 2).setValue(valueData); break; } } } } 
    • Why will the date be received in the format "DD.MM.YYYY 02:00:00". How easy is it to get just a date? - Grigory Druzhinin
    • Select the whole column and apply Format - Numbers - Date joxi.ru/823aa0psJ9gLDr - Sjeurt
    • Works. Another question: The date is entered in the cell that is needed and why is it empty before it goes, why is this happening? Just the data must be written exactly depending on the ID. - Gregory Druzhinin
    • This is strange. I just checked it with my copy-paste code from the answer. I can not reproduce the problem. I'll get home in the evening, think about what could be the matter. - Sjeurt
    • After changing the cells in the format "Date", writes to each cell, regardless of whether there is data there or not. - Grigory Druzhinin