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

275
Vistas
Obtain values of different rows from a prompt and paste them on another sheet

I have a "transporte" sheet where there are hundreds of orders in column D, for which one, I created a prompt where I enter different orders (more than 10), for this I made a code that searches all the rows where these orders are found, and get their values.

The code works up to a certain point, since it finds the rows and their values, but when I paste them in the "envios sheet" they are all overwritten in the same row "2", leaving the last order entered in the prompt, visible in the second row.

My code:

function rutaDinamica() {
  
  var ui = SpreadsheetApp.getUi();
  var result = ui.prompt(
    'Pedidos a transportar?',
    'Ingresa los pedidos:',
    ui.ButtonSet.OK_CANCEL);

  var datos = result.getResponseText().split(" ");
  var boton = result.getSelectedButton();
  var data = [];
  console.log(datos);

  datos.forEach(function (value) {
    const spreadsheetTR = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1F1CEnVvU6Bv9zs38Kx0xo_RCQa1sF0cmmE6DCWa7IAw/edit#gid=0");
    var origen2 = spreadsheetTR.getSheetByName("Transporte");
    const spreadsheet2 = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1UaY9Ch7rpca1LWPLU1TivtssUaC8pILCu-wb_HHoV54/edit#gid=507705369");
    var destino = spreadsheet2.getSheetByName("Envios");
    const depuracionTR = destino.getRange(2, 1, destino.getLastRow(), 10).clearContent();
    var columna = origen2.getRange("D:D")
    var textFinder = columna.createTextFinder(value);
    var ranges = textFinder.findAll();

    if (boton == ui.Button.OK) {
      for (var i = 0; i < ranges.length; i++) {
        var celdas = origen2.setActiveSelection(ranges[i].getA1Notation());
        var filas = celdas.getRowIndex();
        var filasb = origen2.getRange(filas, 1, 1, 10).getDisplayValues();
        Logger.log(filasb);
        data.push(filasb);
      }
    }
    else if (boton == ui.Button.CANCEL) { }
    else if (boton == ui.Button.CLOSE) { }
  });
  const spreadsheet3 = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1UaY9Ch7rpca1LWPLU1TivtssUaC8pILCu-wb_HHoV54/edit#gid=507705369");
  var destino = spreadsheet3.getSheetByName("Envios");
  Logger.log(data);
  destino.getRange(2, 1, data.length, data[0].length).setValues(data);

}
about 4 years ago · Santiago Gelvez
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