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

98
Views
vlookup para diferentes columnas llenando simultáneamente toda la hoja

A continuación se muestra un código que encontré aquí: https://webapps.stackexchange.com/questions/123670/is-there-a-way-to-emulate-vlookup-in-google-script Traté de optimizarlo para mi uso caso en el que vlookup desde la hoja de origen 'datos', y complete los valores en la hoja de destino 's'. El problema es que este código hace esto solo para una fila. ¿Hay alguna manera de recorrer todas las filas y vlookup y completar de manera eficiente?

 /* recall that we want the follwoing columns => E, F, G, H, M /*/ function khalookup(){ var s = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); var data = SpreadsheetApp.openById("mysheetid"); var searchValue = s.getRange("B2:B").getValues(); var dataValues = data.getRange("A3:A").getValues(); var dataList = dataValues.join("ღ").split("ღ"); var index = dataList.indexOf([searchValue]); var newRange = [] var row = index + 3; var foundValue = data.getRange("E"+row).getValue(); var foundValue1 = data.getRange("F"+row).getValue(); var foundValue2 = data.getRange("G"+row).getValue(); var foundValue3 = data.getRange("H"+row).getValue(); var foundValue4 = data.getRange("M"+row).getValue(); s.getRange("K2").setValue(foundValue); s.getRange("L2").setValue(foundValue1); s.getRange("M2").setValue(foundValue2); s.getRange("N2").setValue(foundValue3); s.getRange("O2").setValue(foundValue4); }

aquí está la hoja de origen donde se realizará la búsqueda en función de la ID "Columna A"

hoja de origen

Y así es como se verá la hoja de destino después de que se haya realizado la búsqueda basada en la ID "Columna B".

Hoja de destino

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede iterar con un bucle, por ejemplo, un bucle for

Suponiendo que desea recorrer todas las filas desde index + 3 hasta la última fila , puede modificar su código de la siguiente manera:

 ... var row = index + 3; var lastRow = s.getLastRow(); for (var i = row; i <= lastRow; i++){ var foundValue = data.getRange("E"+i).getValue(); var foundValue1 = data.getRange("F"+i).getValue(); var foundValue2 = data.getRange("G"+i).getValue(); var foundValue3 = data.getRange("H"+i).getValue(); var foundValue4 = data.getRange("M"+i).getValue(); s.getRange("K" + (2+i-row)).setValue(foundValue); s.getRange("L" + (2+i-row)).setValue(foundValue1); s.getRange("M" + (2+i-row)).setValue(foundValue2); s.getRange("N" + (2+i-row)).setValue(foundValue3); s.getRange("O" + (2+i-row)).setValue(foundValue4); }

Tenga en cuenta que, más adelante, es posible que desee pasar de usar getValue() y setValue() a getValues() y setValues() , lo que hará que la ejecución de su código sea más rápida.

about 4 years ago · Juan Pablo Isaza Report
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!