Tip: Other languages are Google-Translated. You can visit the English version of this link.
Log in
x
or
x
x
Register
x

or

How to return multiple lookup values in one comma separated cell?

In Excel, we can apply the VLOOKUP function to return the first matched value from a table cells, but, sometimes, we need to extract all matching values and then separated by a specific delimiter, such as comma, dash, etc… into a single cell as following screenshot shown. How could we get and return multiple lookup values in one comma separated cell in Excel?

doc return multiple values comma separated 1

Return multiple lookup values in one comma separated cell with User Defined Function

Return multiple lookup values in one comma separated cell with Kutools for Excel


Return multiple lookup values in one comma separated cell with User Defined Function

Normally, there is no direct way for us to extract and return the multiple matching values and separated by comma into one cell, here, you can create a User Defined Function to solve this job, please do as follows:

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: Return multiple lookup values into one comma separated cell

Function SingleCellExtract(LookupValue As String, LookupRange As Range, ColumnNumber As Integer, Char As String)
'Updateby20150824
    Dim I As Long
    Dim xRet As String
    For I = 1 To LookupRange.Columns(1).Cells.Count
        If LookupRange.Cells(I, 1) = LookupValue Then
            If xRet = "" Then
                xRet = LookupRange.Cells(I, ColumnNumber) & Char
            Else
                xRet = xRet & "" & LookupRange.Cells(I, ColumnNumber) & Char
            End If
        End If
    Next
    SingleCellExtract = Left(xRet, Len(xRet) - 1)
End Function

3. Then save this code and close the Module window, go back to your worksheet, and enter this formula: =SingleCellExtract(D2,A2:B15,2,",") into a blank cell that you want to return the result. And then press Enter key to get the result, see screenshot:

doc return multiple values comma separated 2

Note: In the above formula:

D2: indicates the cell values that you want to look up;

A2: B15: is the data range that you want to fetch the data;

2: the number 2 is the column number that matching value is to be returned;

,: the comma is the separator that you want to separate the multiple values.

You can change them to your need.


Return multiple lookup values in one comma separated cell with Kutools for Excel


If you have Kutools for Excel, this task will no longer be a problem. The Advanced Combine Rows utility may help you combine all relative values based on a 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 combine all matching values based on a column.

2. Click Kutools > Content > Advanced Combine Rows, see screenshot:

doc return multiple values comma separated 3

3. In the Combine Rows Based on Column dialog box, click the column name that you want to combine based on, and then click Primary Key button, see screenshot:

doc return multiple values comma separated 4

4. Then click other column name that you want to combine their matched values, and click Combine to choose one separator to separate the combined values, see screenshot:

doc return multiple values comma separated 5

5. Then click OK button, all the corresponding cells with the same value have been combined into one cell which are separated with the comma, see screenshots:

doc return multiple values comma separated 6  2 doc return multiple values comma separated 7

Click to know more details about this Advanced Combine Rows utility…

Download and free trial Kutools for Excel Now !


Demo: Return multiple lookup values in one comma separated cell with Kutools for Excel

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!


Excel Productivity Tools

Ribbon of Excel (with Kutools for Excel installed)

300+ Advanced Features Increase Your Productivity by 70%, and Help You To Stand Out From Crowd!

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 80% 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!

Office Tab Brings Efficient And Handy Tabs to Office (include Excel), Just Like Chrome, Firefox, And New IE

  • 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!
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.
    Js · 1 years ago
    VB command breaks when the range is longer than 154 rows (ie :B154)....
  • To post as a guest, your comment is unpublished.
    M Macklam · 1 years ago
    thank you, firstly i managed to get this to work without the slow down in performance. I'm using values rather that text so my question is i want to bring back all those with less than say 19 points in a list. Can the single cell Extract work for that or does it have to be a specific value?
  • To post as a guest, your comment is unpublished.
    A Ward · 1 years ago
    This simply does not work. I was unable to get it to work in my own application, so I copy/pasted the vba and the formula and it returned an error every time
  • To post as a guest, your comment is unpublished.
    K Ray · 1 years ago
    This works but slows down my excel majorly! Any tips to help speed?
  • To post as a guest, your comment is unpublished.
    Guest · 1 years ago
    Thanks for this post. Do you know how I would go about manipulating the two separate integers this is creating. For example, lets say that the '=SingleCellExtract' function now produces (1 , 2). Is there a way to have a cell next to it that does (1+.5 , 2+.5)?