0

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.

Rubén
  • 34,714
  • 9
  • 70
  • 166
Lucas Moreira
  • 29
  • 3
  • 12

2 Answers2

2

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.

Mr.Rebot
  • 6,703
  • 2
  • 16
  • 91
1

You can pass list of value using batchupdate

Raval Sneh
  • 31
  • 4