How to vlookup and concatenate multiple corresponding values in Excel?
As we all known, the Vlookup function in Excel can help us to lookup a value and return the corresponding data in another column, but in general, it can only get the first relative value if there are multiple matching data. In this article, I will talk about how to vlookup and concatenate multiple corresponding values in only one cell or a vertical list.
Vlookup and return multiple matching values vertically with formula
Vlookup and concatenate multiple matching values in a cell with User Defined Function
Vlookup and concatenate multiple matching values in a cell with Kutools for Excel
Vlookup and concatenate multiple matching values in a 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.
- 1. Specify the key column that you want to combine other column based on;
- 2. Choose the separator for your combined data.
Supposing, I have the following range of data, to get all the corresponding values based on a specific value vertically as following screenshot shown, you can apply an array formula.
1. Enter this formula: =IF(COUNTIF($A$1:$A$16,$D$2)>=ROWS($1:1),INDEX($B$1:$B$16,SMALL(IF($A$1:$A$16=$D$2,ROW($1:$16)),ROW(1:1))),"") into a blank cell where you want to put the result, for example, E2, and then press Ctrl + Shift + Enter keys together to get the relative value base on a specific criterion, see screenshot:
Note: In the above formula:
A1:A16 is the column range which contains the specific value you want to look for;
D2 indicates the specific value you want to vlookup;
B1:B16 is the column range that you want to return the corresponding data from;
$1:$16 indicates the rows reference within the range.
2. Then select cell E2, and drag the fill handle down to the cells until you get blank cells, and all matching values are listed into the column as following screenshot shown:
Instead of getting the relative values vertically, sometimes, you want to the matching values into one cell and concatenate them with a specific separator. In this case, the following User Defined Function may do you a favor.
1. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications window.
2. Click Insert > Module, and paste the following code in the Module Window.
VBA code: Vlookup and concatenate multiple matching values in a cell
Function CusVlookup(lookupval, lookuprange As Range, indexcol As Long)
'updateby Extendoffice 20151118
Dim x As Range
Dim result As String
result = ""
For Each x In lookuprange
If x = lookupval Then
result = result & " " & x.Offset(0, indexcol - 1)
CusVlookup = result
3. Then save and close this code, go back to the worksheet, and enter this formula: =cusvlookup(D2,A1:B16,2) into a blank cell where you want to put the result, and press Enter key, all corresponding values based on a specific data have been returned into one cell with space separator, see screenshot:
Note: In the above formula: D2 indicates the cell values that you want to look up, A1: B16 is the data range that you want to fetch the data, the number 2 is the column number that the matching value is to be returned from, you can change theses references to your need.
If you have Kutools for Excel, with its Advanced Combine Rows feature, you can quickly finish this job with ease. This feature can help you to combine all matching values with a specific delimiters based on the same data in another column.
|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 get the corresponding values based on the specific data.
2. Then click Kutools > Content > Advanced Combine Rows, see screenshot:
3. In the Advanced Combine Rows dialog box, click the column name that you want to combine based on, then click Primary Key button, see screenshot:
4. Then click another column name that you want to return the matched values, and click Combine to choose one separator to separate the combined values, see screenshot:
5. And then click Ok button, all the corresponding values based on same values have been combined together with a specific separator, see screenshots:
Download and free trial Kutools for Excel Now !
Recommended Productivity Tools
Would you like to complete your daily work quickly and perfectly? Kutools For Excel brings
300+ cool and powerful advanced features (Combine workbooks, sum by color, split cell contents, convert date, and so on...) for
1500+ work scenarios, helps you solve
82% Excel problems.
- Deal with all complicated tasks in seconds, help to enhance your work ability, get success from the fierce competition, and never worry about being fired.
- Save a lot of work time, leave much time for you to love and care the family and enjoy a comfortable life now.
- Reduce thousands of keyboard and mouse clicks every day, relieve your tired eyes and hands, and give you a healthy body.
- Become an Excel expert in 3 minutes, and get admiring glance from your colleagues or friends.
- No longer need to remember any painful formulas and VBA codes, have a relaxing and pleasant mind, give you a thrill you've never had before.
- Spend only $39, but worth than $4000 training of others. Being used by 110,000 elites and 300+ well-known companies.
- 60-day unlimited free trial. 60-day money back guarantee. Free upgrade and support for 2 years. Buy once, use forever.
- Change the way you work now, and give you a better life immediately!
- Increases your productivity by
50% when viewing and editing multiple documents.
- Reduce hundreds of mouse clicks for you every day, say goodbye to mouse hand.
- Open and create documents in new tabs of same window, rather than in new windows.
- Help you work faster and easily stand out from the crowd! One second to switch between dozens of open documents!