Consejo: Otros idiomas son traducidos por Google. Puedes visitar el English versión de este enlace.
Iniciar sesión
x
or
x
x
Suscríbete
x

or

¿Cómo vlookup para devolver múltiples valores en una celda en Excel?

Normalmente, en Excel, cuando utiliza la función VLOOKUP, si hay varios valores para que coincidan con los criterios, puede obtener el primero. Pero, a veces, desea devolver todos los valores correspondientes que cumplen los criterios en una celda como se muestra a continuación, ¿cómo podría resolverlo?

Vlookup para devolver múltiples valores en una celda con la función definida por el usuario

Vlookup para devolver múltiples valores en una celda con kutools para Excel

doc-vlookup-multiple-values-one-cell-1


Vlookup para devolver múltiples valores correspondientes en una sola celda:

Con Kutools for Excel, Filas de combinación avanzadas de hecho, puede combinar rápidamente múltiples filas duplicadas en un registro basado en columnas clave, y también puede aplicar algunos cálculos como suma, promedio, recuento, etc. para otras columnas.

  • 1. Especifique la columna clave en la que desea combinar otra columna;
  • 2. Elija el separador para sus datos combinados.

doc combine el texto basado en los criterios 10

Kutools for Excel: con más de 200 útiles complementos de Excel, de prueba sin límite en días 60. Descargar y prueba gratis ahora!

>

La función VLOOKUP tradicional puede no ayudarlo a resolver este problema, pero crearé una Función definida por el usuario para que usted se encargue de esta tarea. Por favor haz lo siguiente:

1. Active su hoja de cálculo que desea visualizar valores múltiples en una celda.

2. Mantenga presionado el ALT + F11 llaves, y abre la Ventana de Microsoft Visual Basic para Aplicaciones.

3. Hacer clic recuadro > Móduloy pegue el siguiente código en Ventana de módulo.

Código VBA: Vlookup para devolver múltiples valores en una celda

Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)
'Update 20150310
Dim rng As Range
Dim xResult As String
xResult = ""
For Each rng In pWorkRng
    If rng = pValue Then
        xResult = xResult & " " & rng.Offset(0, pIndex - 1)
    End If
Next
MYVLOOKUP = xResult
End Function

4. A continuación, guarde y cierre este código, vuelva a la hoja de trabajo e ingrese esta fórmula: = myvlookup (E6, $ A $ 2: $ C $ 15,2) en una celda en blanco específica donde desea colocar el resultado, luego presione entrar clave para obtener todos los valores correspondientes en una celda que desee, consulte la captura de pantalla:

doc-vlookup-multiple-values-one-cell-2

Nota:

En la fórmula anterior: E6 es el valor que desea devolver su información relativa, A2: C15 es el rango de datos que usa, el número 2 indica el número de columna que devuelve el valor coincidente.


Si tienes nuestro Kutools for Excel, Con su Filas de combinación avanzadas función, puede fusionar o combinar rápidamente las filas en función del mismo valor y hacer algunos cálculos.

Kutools for Excel : con más de 300 útiles complementos de Excel, de prueba sin límite en días 60.

Después de instalar Kutools for Excel, haz lo siguiente:

1. Seleccione el rango de datos que desea combinar datos de una columna en función de otros datos.

2. Hacer clic Kutools > Contenido > Filas de combinación avanzadas, mira la captura de pantalla:

doc-vlookup-multiple-values-one-cell-5

3. En el Combinar filas basadas en columna cuadro de diálogo, haga clic en la columna clave para combinar en función de, y luego haga clic Clave primaria. A continuación, haga clic en otra columna que desee combinar sus datos en función de la columna de clave, y haga clic Combinar para elegir un separador para separar los datos combinados, vea la captura de pantalla:

doc-vlookup-multiple-values-one-cell-6

4. A continuación, haga clic en OK botón, y obtendrá los siguientes resultados:

doc-vlookup-multiple-values-one-cell-3 -2 doc-vlookup-multiple-values-one-cell-4-4

Haga clic para obtener más información sobre esta función avanzada de combinación de filas.

Descargue y pruebe de forma gratuita Kutools for Excel Now!


Kutools for Excel: con más de 200 útiles complementos de Excel, de prueba sin límite en días 60. Descargar y prueba gratis ahora!


Artículos relacionados:

¿Cómo visualizar el siguiente valor más grande en Excel?

¿Cómo vlookup en una tabla bidimensional en Excel?

¿Cómo dar vuelta a otro libro de trabajo?


Kutools for Excel: la mejor herramienta de productividad de Office aumenta su productividad en un 80%

  • Super Formula Bar (edite fácilmente varias líneas de texto y fórmula); Diseño de lectura (lee y edita fácilmente un gran número de celdas); Pegar en rango filtrado...
  • Combinar celdas / filas / columnas y mantener datos; Contenido de celdas divididas; Combinar filas duplicadas y suma / promedio... Prevenir células duplicadas; Comparar rangos...
  • Seleccione Duplicado o Único Filas; Seleccionar filas en blanco (todas las celdas están vacías); Super Find y Fuzzy Find en muchos libros de trabajo; Selección aleatoria ...
  • Copia exacta Celdas múltiples sin cambiar la referencia de fórmula; Crear referencias automáticamente a múltiples hojas; Insertar viñetas, Casillas de verificación y más ...
  • Fórmulas favoritas e insertadas rápidamente, Gamas, cuadros y cuadros; Cifrar celdas con contraseña Crear una lista de correo y enviar correos electrónicos ...
  • Extracto del texto, Agregar texto, Eliminar por posición, Eliminar espacio; Crear e imprimir subtotales de paginación; Convertir entre contenido de celdas y comentarios...
  • Súper filtro (guardar y aplicar esquemas de filtro a otras hojas); Clasificación avanzada por mes / semana / día, frecuencia y más; Filtro especial por negrita, cursiva ...
  • Combinar libros de trabajo y hojas de trabajo; Combinar tablas basadas en columnas clave; Dividir datos en varias hojas; Conversión por lotes xls, xlsx y PDF...
  • Funciona con Office 2007-2019 y 365, y es compatible con todos los idiomas. Es fácil de implementar en su empresa. Funciones completas de prueba gratuita de 60-day.
pestaña kte 201905

Office Tab lleva la interfaz con pestañas a Office y hace que su trabajo sea mucho más fácil

  • Habilitar la edición y lectura con pestañas en Word, Excel, PowerPoint, Editor, Acceso, Visio y Proyecto.
  • Abra y cree varios documentos en nuevas pestañas de la misma ventana, en lugar de en nuevas ventanas.
  • ¡Aumenta tu productividad en un 50% y reduce cientos de clics de ratón por ti todos los días!
fondo officetab
Say something here...
symbols left.
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
Loading comment... The comment will be refreshed after 00:00.
  • To post as a guest, your comment is unpublished.
    Steven · 21 days ago
    Thank you. I just modified so that it will replace the comma at the start and replace the last comma with "And".

    (Working with states)

    Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)

    Dim rng As Range
    Dim xResult, States As String
    Dim Pos As Long
    xResult = ""
    For Each rng In pWorkRng
    If rng = pValue Then
    xResult = xResult & ", " & rng.Offset(0, pIndex - 1)
    End If
    Next
    States = Right(xResult, Len(xResult) - 2)
    Pos = InStrRev(States, ",")

    If Pos > 1 Then
    States = Mid(States, 1, Pos - 1) & Replace(States, ",", " AND", Pos)

    End If

    MYVLOOKUP = States
    End Function
  • To post as a guest, your comment is unpublished.
    Devinder Kaur · 4 months ago
    do we have the code to work it from last to first. like we have multiple values in columnB and we want them in row with column A remain same.
  • To post as a guest, your comment is unpublished.
    Pam · 9 months ago
    For some reason this macro is extremely slow for me, every time I click anywhere it takes about 5-10 minutes to calculate.
  • To post as a guest, your comment is unpublished.
    Alex · 10 months ago
    Tthat's what I wanted! Thank you very much XD
  • To post as a guest, your comment is unpublished.
    Tom T · 1 years ago
    This is amazing, thank you!
  • To post as a guest, your comment is unpublished.
    Mark · 1 years ago
    Great function, however chunking through 100,000 records proves a bit much for my poor laptop, will need to let it run overnight!
  • To post as a guest, your comment is unpublished.
    Will · 1 years ago
    Is there a way of amending the result so instead of showing 1000 1000 -1000 it would show for example 1,000/1,000/(1,000) ?
  • To post as a guest, your comment is unpublished.
    Kabilankumar · 2 years ago
    Great macro, useful.

    But need to know can it be modified to check 2 criteria & does anyone found anyway to make wildcards work on it.

    Any help?
  • To post as a guest, your comment is unpublished.
    Jay · 2 years ago
    No matter what I do, I always get #value! returned instead of a result. vlookup works just fine, so the data works. Already followed the process of enabling macros. I even combined everything into a single sheet. Any ideas??
  • To post as a guest, your comment is unpublished.
    Curtis · 2 years ago
    This worked perfectly, but it did take me some time to get the Function work properly within my 20 tab, 50k+ line spreadsheet.
    Now the BIG question is how to take that delimited string and then use each entry as an Index/Match (not married to Index/Match, but it seems faster) lookup value in another dataset, returning the SUM value of all returns into one cell. My scenario is that I have a Single Order that has multiple invoices. Your MYVLOOKUP Function works superbly to report back all of the invoices in one cell. What I want to do now is to take each concatenated return with the reported cell, spin through that array and total the amounts of payment of each invoice back into the formula cell.

    I appreciate any help that you can offer on this and thanks for the MYVLOOKUP Function!
  • To post as a guest, your comment is unpublished.
    Alex Chow · 2 years ago
    To get unique record, you may use below: (modified by refer other user code)


    Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)
    'Update 20150310
    'Updated 6/9/16 Jay Coltrain
    'Dim rng As Range
    Dim xResult As String
    xResult = ""

    Dim Rows As Long, i As Long
    Rows = pWorkRng.Rows.Count

    For i = 1 To Rows
    If pWorkRng.Cells(i, 1).Value = pValue Then
    xResult = xResult & "," & pWorkRng.Cells(i, 1).Offset(0, pIndex - 1)
    End If
    Next i

    Dim varSection As Variant
    Dim sTemp As String
    Dim sDelimiter As String

    sDelimiter = ","

    For Each varSection In Split(xResult, sDelimiter)
    If InStr(1, sDelimiter & sTemp & sDelimiter, sDelimiter & varSection & sDelimiter, vbTextCompare) = 0 Then
    sTemp = sTemp & sDelimiter & varSection
    End If
    Next varSection


    MYVLOOKUP = Mid(sTemp, Len(sDelimiter) + 1)
    End Function
  • To post as a guest, your comment is unpublished.
    Spyros Tzortzis · 2 years ago
    Heads-up. I figured out how to get any separator in that output. Its rudimentary. But I figured it out.

    xResult = xResult & "///" & rng.Offset(0, pIndex - 1)

    The last and most wished for thing though is enabling it to work with wildcards in the search criteria. Thank you again for this beautiful and brilliant solution. Extremely helpful. Now just want to get get the macro to run and be installed in my excel perminantly no matter what I'm doing so I can use it when I need to.

    And wildcards!

    Thank you so much.

    Wildcards are all that are left to do.
  • To post as a guest, your comment is unpublished.
    Spyros Tzortzis · 2 years ago
    Hi,

    It works well. What I would like to do is adapt the code to seperate thee value results with "///" or any other marker (for technical reasons, I don't want just a single character seperator).

    Also, I noticed that this formula doesnt work with a wild card. I know i am asking too much, but it doesnt as vlookup can work when i search for =myvlookup("*"&E6&"*",$A$2:$C$15,2) which it would do/could do.

    Any assistance?
  • To post as a guest, your comment is unpublished.
    Ajay · 2 years ago
    Return nothing! after applying MYLOOKUP giving no result but blank.
  • To post as a guest, your comment is unpublished.
    Rob · 2 years ago
    Notify me of follow-up comments
  • To post as a guest, your comment is unpublished.
    cory · 3 years ago
    This works great, but I still need help with the command function to remove duplicates from the results.
  • To post as a guest, your comment is unpublished.
    cory · 3 years ago
    This works great, but I need help with the command to remove duplicates from the results. Seriously though, Great work.
  • To post as a guest, your comment is unpublished.
    Jay · 3 years ago
    This is exactly what I was looking for and did not think of just making my own UDF. However it will not function exactly like VLOOKUP. If the string you are looking for is not only in the first column then it could give you data outside the original range passed.

    Name Number Other name Column not in range passed
    Jay 1 Jay 1
    Jay 2 Jay 2
    Chris 3 Chris 3
    Jorge 4 Jorge 4
    Jay 5 Jay 5
    Jorge 6 Jorge 6

    If the above table were cells A1:D7 if you passed only A1:C7 your "MYVLOOKUP" function returns 1 1 2 2 5 5 when you would expect it to return 1 2 5.

    The changes below fix the issue:

    Function MYVLOOKUP(pValue As String, pWorkRng As Range, pIndex As Long)
    'Update 20150310
    'Updated 6/9/16 Jay Coltrain
    'Dim rng As Range
    Dim xResult As String
    xResult = ""

    Dim Rows As Long, i As Long
    Rows = pWorkRng.Rows.Count

    For i = 1 To Rows
    If pWorkRng.Cells(i, 1).Value = pValue Then
    xResult = xResult & " " & pWorkRng.Cells(i, 1).Offset(0, pIndex - 1)
    End If
    Next i

    'For Each rng In pWorkRng
    ' If rng = pValue Then
    ' xResult = xResult & " " & rng.Offset(0, pIndex - 1)
    ' End If
    'Next
    MYVLOOKUP = xResult
    End Function
  • To post as a guest, your comment is unpublished.
    Ari · 3 years ago
    Thank you for the VBA-code. I got exactly what I want!

    I modified only the code " rng.Offset(0, pIndex - 1) " to " rng.Offset(0, pIndex - 2) " . So is MYVLOOKUP able to search from Right to Left.
  • To post as a guest, your comment is unpublished.
    Ankit Jain · 3 years ago
    Hi,
    i am really impressed with the work and its so easy to create one to use this function. however i need further support.

    My ? is that how can i select a number from a cell with multiple cell in my vlookup array. i.e.

    If cell A1 = 100, A2 = 350, A3 = 69

    C1 = 100; 1222; 12133
    C2 = 69; 222
    D1 = Apple
    D2 = banana

    So how can select 100 from my table array column C to derive correspondent D1 = apple

    Please note that i have 7 digit numbers in my lookup value and table array which is separated by a ";". I would really appreciate if you can solve this and help me in saving a lot time.
  • To post as a guest, your comment is unpublished.
    Ajay · 3 years ago
    Awesome work.. Got exactly what I want !!! Love it !!
  • To post as a guest, your comment is unpublished.
    Colleen · 3 years ago
    Thank you for sharing the above code. I've been using this for several months now but today it doesn't seem to work. I'm getting blank cells instead of the usual error when there is data to be returned. Any thoughts?
  • To post as a guest, your comment is unpublished.
    David V · 3 years ago
    Thanks for the VBA code above. Can you tell me how to make the results enter onto a new line in the cell, ie like Alt-Enter
    300
    400
    1000
    1300
  • To post as a guest, your comment is unpublished.
    David Atwell · 4 years ago
    How would I adjust this formula to separate each returned value but ", " as well as only return unique values?