简体   繁体   中英

How to set a code to a cell if another isn't null Google SpreadSheet

Hi I want to do a script in the GoogleSpreadSheet like this:

 var celula = 'B2'
 var celula2 = 'B3'
 var linha = 'S2';
 var linha2 = 'S3';
 if (celula != null); {
 SpreadsheetApp.getActiveSheet().getRange(linha).setValue("ITDS001");
 }
 if (celula2 != null); {
 SpreadsheetApp.getActiveSheet().getRange(linha2).setValue("ITDS002");
 }

But instead of making it one by one I would like to know how to do a for with a i++ to get all cells from column B and all cells of column S and **if cells of column"B" +i are not null, set "ITDS"(String code) +i (1,2,3,etc) to cells on column "S"i **.

It would be like: if B2 is not null set ITDS001 to S2, if B3 is not null set ITDS002 to S3 and so on.

This may depend on your implementation. As you can see in this related SO post's answer :

function checkNupdate(){
var ss = SpreadsheetApp.getActiveSheet();
var len = ss.getLastRow();
for(var i = 1 ; i < len +1  ; i++){
    var num1 = ss.getRange("D"+i).getValue(); 
    var num2 = ss.getRange("E"+i).getValue();
    ss.getRange("E"+i).setValue(num1+num2); 
    ss.getRange("D"+i).clear(); 
  }
}

You can set a for loop to check the column if it is empty then put a value on a specific column/row. But you can also check the answer of @Raval and use Sheets API batch request.

Hope this helps.

您可以使用batchupdate传递值列表

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM