Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
How to use the result of an IF statement as a variable

I have a code as follows:

function DetailFacture2() {
  var ss = SpreadsheetApp.getActive();
  var DetailDEVIS = SpreadsheetApp.setActiveSheet(ss.getSheetByName('DetailDEVIS'));
  var FACTUREDevis = SpreadsheetApp.setActiveSheet(ss.getSheetByName('FACTUREDevis'));
  var DetailFactureDevis = SpreadsheetApp.setActiveSheet(ss.getSheetByName('DetailFactureDevis'));
  var lastrowpaste = FACTUREDevis.getLastRow();
  var numrow = FACTUREDevis.getRange(lastrowpaste,13).getValue()
  var lastrowpaste2 = DetailFactureDevis.getLastRow() - numrow +2;
  var data = DetailDEVIS.getDataRange().getValues();
  var DetailD = FACTUREDevis.getRange(lastrowpaste,2).getValue();
  for(var i = 0; i<data.length;i++){
    if(data[i][1] == DetailD){ //[1] because column B
      var firstrowcopy = i+1;
      Logger.log(firstrowcopy)
      return (firstrowcopy)
    }
  }
};

It does return the correct value, but how do you use "firstrowcopy" as a fixed var? I would like to use as follows:

function DetailFacture2() {
  var ss = SpreadsheetApp.getActive();
  var DetailDEVIS = SpreadsheetApp.setActiveSheet(ss.getSheetByName('DetailDEVIS'));
  var FACTUREDevis = SpreadsheetApp.setActiveSheet(ss.getSheetByName('FACTUREDevis'));
  var DetailFactureDevis = SpreadsheetApp.setActiveSheet(ss.getSheetByName('DetailFactureDevis'));
  var lastrowpaste = FACTUREDevis.getLastRow();
  var numrow = FACTUREDevis.getRange(lastrowpaste,13).getValue()
  var lastrowpaste2 = DetailFactureDevis.getLastRow() - numrow +2;
  var data = DetailDEVIS.getDataRange().getValues();
  var DetailD = FACTUREDevis.getRange(lastrowpaste,2).getValue();
  for(var i = 0; i<data.length;i++){
    if(data[i][1] == DetailD){ //[1] because column B
      var firstrowcopy = i+1;
      var source = DetailDEVIS.getRange(firstrowcopy,1,numrow-1);
      var destination = DetailFactureDevis.getRange(lastrowpaste2,3);
      source.copyTo(destination);
    }
  }
};

But, as one would expect, it cannot work as it loops...

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Not sure if I understand your question too. The code doesn't look well. Here is just my guess. Try to change the last lines this way:

// ...

  var firstrowcopy = 0;
  for (var i = 0; i < data.length; i++){
    if(data[i][1] == DetailD){ //[1] because column B
      firstrowcopy = i+1;
      break;
    }
  }

  var source = DetailDEVIS.getRange(firstrowcopy,1,numrow-1);
  var destination = DetailFactureDevis.getRange(lastrowpaste2,3);
  source.copyTo(destination);
}
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda