How to speed up the running time of Google Apps Script?

Asked

Viewed 261 times

2

I am beginner in the world of programming, I created a script to go through table 1 and bring the values as they are in table 2 according to the periods informed in it.

The script works correctly but it is very slow at the time of execution. I would like a help to try to make it faster.

I researched about matrices but could not understand to apply in this function.

function teste() {

  var ss = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Página6");
  var tabela = ss.getRange(3, 9, ss.getLastRow(), 1).getValues();

  for(var l1 = 3 ; l1 <= tabela.length ; l1 ++ ){
    var tab1 = ss.getRange(l1,8).getValue();
    for( var l2 = 3 ; l2 <= tabela.length ; l2 ++ ){
      var tab2 = ss.getRange(l2,12).getValue();

      if (tab1 == tab2){

        for( var col = 13 ; col < 17 ; col ++){
             var coluna = ss.getRange(2, col).getValue();

          if( ss.getRange(l1, 9).getValue() == ss.getRange(2, col).getValue()){
               ss.getRange(l2, col).setValue(ss.getRange(l1, 10).getValue());
          }
        }
      }
    }
  } 
}

Imagem mostrando a tabela

  • this is the site of the OS in Portuguese, translate your question

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.