Vlookup - return multiple values in one cell (Concatenate?)

dixon1983

Board Regular
Joined
Apr 23, 2005
Messages
175
Hi,
I have a sheet like the one below:

A B
1 34
1 32
1 20
2 10
2 4
2 9
2 100


I would like to use a vlookup that looks up the value in column A and returns a string of all the values in B. E.g If i was looking up 1 it would return 34 32 20 as one text string.

I'm not too good at Arrays and Indexes etc so don't know what to use to do this.

Any help would be greatly appreciated. Many Thanks in advance.

Dixon
 
Try this custom function:
Code:
Function MYVLOOKUP(lookupval, lookuprange As Range, indexcol As Long)
Dim r As Range
Dim result As String
result = ""
For Each r In lookuprange
    If r = lookupval Then
        result = result & " " & r.Offset(0, indexcol - 1)
    End If
Next r
MYVLOOKUP = result
End Function

Then type:
Code:
=MYVLOOKUP(A1,A1:A20,2)

I know that this has been around a little while but I am hoping that someone can still help.

My Lookup Range has some fields with blank values. This is then showing as a blank space in the cell.

Additionally, I would quite like to enter a '/' instead of a space in between each result. any advice for this?

Many thanks,
Michael
 
Upvote 0

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
thanks for the VBA.

how can I put each value from VLOOKUP in different cell?

example: I use MYVLOOKUP on cell A2 and then on cell A2, A3, A4, A5 it will return each value.

best regards.

I have amended the code to fit your needs. I know this was months ago, but someone else maybe looking for the same solution.
Code:
Function MYVLOOKUP(lookupval, lookuprange As Range, indexcol As Long)
Dim r As Range
Dim result As String
result = ""
Dim i As Integer
i = 0
For Each r In lookuprange
    If r = lookupval And i <= 4 Then
        result = result & " " & r.Offset(0, indexcol - 1) & Chr(10)
        i = i + 1
    End If
    Next r
MYVLOOKUP = result
End Function
 
Upvote 0
Try this custom function:
Code:
Function MYVLOOKUP(lookupval, lookuprange As Range, indexcol As Long)
Dim r As Range
Dim result As String
result = ""
For Each r In lookuprange
    If r = lookupval Then
        result = result & " " & r.Offset(0, indexcol - 1)
    End If
Next r
MYVLOOKUP = result
End Function

Then type:
Code:
=MYVLOOKUP(A1,A1:A20,2)

The formula is perfect for my needs, other than - I need the output to still be in one cell, but each result to be on a new line in that cell? What would I need to change please.

EDIT: Ignore sorry, found an updated version
 
Last edited:
Upvote 0
Hi the code above works perfectly fine! There is just one this if you can help me with.

How can i eliminate duplicate values if i have any in my list ?
 
Upvote 0
This has been covered multiple times in multiple posts, this one that has the link for the best formula for this I've found so far.
 
Upvote 0
Hi, Thank you all for the VB script.

i have found that the MYVLOOKUP does not support wildcard in excel "*"&A1&"*". Can anyone help how to make this happen?
 
Upvote 0
HI VenKat - can you also try and help me some VBA code: I have three columns. Column A has the name of the fruit juice, Column B the size of the bottle and Column C the value. I need to match the product with size and add values to a single cell. In the example: = Mango 350ml 7000.000 or Apple 500ml 21620.00

Mango350ML R 5,000.00
Mango350 R 2,000.00
Mango250 R 3,000.00
Mango250 R 6,000.00
Mango125 R 1,200.00
Tropical125 R 4,000.00
Apple125 R 8,000.00
Apple500 R 9,000.00
Apple500 R 7,000.00
Apple500 R 5,620.00
Tropical350 R 3,526.00
Tropical350 R 2,545.00
Tropical350 R 5,895.00

<colgroup><col><col><col></colgroup><tbody>
</tbody>
 
Upvote 0
HI VenKat - can you also try and help me some VBA code: I have three columns. Column A has the name of the fruit juice, Column B the size of the bottle and Column C the value. I need to match the product with size and add values to a single cell. In the example: = Mango 350ml 7000.000 or Apple 500ml 21620.00

Mango350ML R 5,000.00
Mango350 R 2,000.00
Mango250 R 3,000.00
Mango250 R 6,000.00
Mango125 R 1,200.00
Tropical125 R 4,000.00
Apple125 R 8,000.00
Apple500 R 9,000.00
Apple500 R 7,000.00
Apple500 R 5,620.00
Tropical350 R 3,526.00
Tropical350 R 2,545.00
Tropical350 R 5,895.00

<tbody>
</tbody>
This is a different situation -related, but, is not the same-
For this, you have a native solution, "sum if"
Just try to organize your data prior.
Example:
(as you may notice, STD the 350ML for 350 instead and the real Qty for the number
ABCDFormulaResult
Mango350R 5,000.005000=SUMIFS(D:D;A:A;A1;B:B;B1)7000
Mango350R 2,000.002000=SUMIFS(D:D;A:A;A2;B:B;B2)7000
Mango250R 3,000.003000=SUMIFS(D:D;A:A;A3;B:B;B3)9000
Mango250R 6,000.006000=SUMIFS(D:D;A:A;A4;B:B;B4)9000
Mango125R 1,200.001200=SUMIFS(D:D;A:A;A5;B:B;B5)1200
Tropical125R 4,000.004000=SUMIFS(D:D;A:A;A6;B:B;B6)4000
Apple125R 8,000.008000=SUMIFS(D:D;A:A;A7;B:B;B7)8000
Apple500R 9,000.009000=SUMIFS(D:D;A:A;A8;B:B;B8)21620
Apple500R 7,000.007000=SUMIFS(D:D;A:A;A9;B:B;B9)21620
Apple500R 5,620.005620=SUMIFS(D:D;A:A;A10;B:B;B10)21620
Tropical350R 3,526.003526=SUMIFS(D:D;A:A;A11;B:B;B11)11966
Tropical350R 2,545.002545=SUMIFS(D:D;A:A;A12;B:B;B12)11966
Tropical350R 5,895.005895=SUMIFS(D:D;A:A;A13;B:B;B13)11966

<colgroup><col><col span="3"><col><col></colgroup><tbody>
</tbody>
 
Last edited:
Upvote 0
Building upon the formula in post #2, here is a formula for extracting unique items. Hope this helps.
Mike Szczesny


Excel 2012
ABCDE
11aa1
21bb
31cc
41cd
51dj
61ap
71js
82an
91p
102r
111s
121s
132t
141n
151a
16
Sheet1
Cell Formulas
RangeFormula
D1{=IFERROR(INDEX($B$1:$B$15,SMALL(IF(FREQUENCY(IF($A$1:$A$15=$E$1,MATCH($B$1:$B$15,$B$1:$B$15,0)),ROW($B$1:$B$15)-ROW($B$1)+1),ROW($B$1:$B$15)-ROW($B$1)+1),ROWS($D$1:D1)))," ")}
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Hi all,

I really need some help, I am not sure if its because its nearly midnight here but I am struggling to adapt the above formulas to get the results I need. I have 2 spreadsheets, one lists customers names and fleet size i.e.

Row LabelsFleet Size
Customer A2

<tbody>
</tbody>


I then have another spreadsheet listing the customers and registrations i.e.

CustomerRegistration number
Customer A

Customer A
Reg 1

Reg 2

<tbody>
</tbody>


What I want is a formula to put into the first sheet which will show me the registrations for that customer but in one cell if possible.

So it looks like the below.

Row LabelsFleet SizeRegistrations
Customer A2Reg 1, Reg 2

<tbody>
</tbody>


I would be really grateful if you could help.
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,547
Members
449,089
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top