Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

274
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!