How to vlookup to return multiple values in one cell in Excel?
Normally, in Excel, when you use the VLOOKUP function, if there are multiple values to match the criteria, you just can get the first one. But, sometimes, you want to return all the corresponding values which meet the criteria into one cell as following screenshot shown, how could you solve it?
Vlookup to return multiple corresponding values in one single cell:
With Kutools for Excel’s Advanced Combine Rows utiltiy, you can quickly combine multiple duplicate rows into one record based on key columns, and it also can apply some calculations such as sum, average, count and so on for other columns.
Kutools for Excel: with more than 200 handy Excel add-ins, free to try with no limitation in 60 days. Download and free trial Now!
The traditional VLOOKUP function may not help you to solve this problem, but, I will create a User Defined Function for you to deal with this task. Please do as follows:
1. Activate your worksheet which you want to vlookup multiple values into one cell.
2. Hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.
3. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Vlookup to return multiple values in one cell
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. Then save and close this code, go back to the worksheet, and enter this formula: =myvlookup(E6,$A$2:$C$15,2) into a specific blank cell where you want to place the result, then press Enter key to get all the corresponding values in one cell that you want, see screenshot:
In the above formula: E6 is the value which you want to return its relative information, A2:C15 is the data range you use, the number 2 indicates the column number that your matched value is returned.
If you have our Kutools for Excel, with its Advanced Combine Rows feature, you can quickly merge or combine the rows based on the same value and do some calculations.
|Kutools for Excel : with more than 300 handy Excel add-ins, free to try with no limitation in 60 days.|
After installing Kutools for Excel, please do as follows:
1. Select the data range that you want to combine one column data based on another data.
2. Click Kutools > Content > Advanced Combine Rows, see screenshot:
3. In the Combine Rows Based on Column dialog box, click the key column to be combined based on, and then click Primary Key. Then click another column that you want to combine its data based on the key column, and click Combine to choose one separator for separating the combined data, see screenshot:
4. Then click OK button, and you will get the following results:
Recommended Productivity Tools
You are guest ( Sign Up? )
or post as a guest, but your post won't be published automatically.
To post as a guest, your comment is unpublished.· 1 months agodo 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.· 6 months agoFor 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.· 7 months agoTthat's what I wanted! Thank you very much XD
To post as a guest, your comment is unpublished.· 9 months agoThis is amazing, thank you!
To post as a guest, your comment is unpublished.· 10 months agoGreat function, however chunking through 100,000 records proves a bit much for my poor laptop, will need to let it run overnight!