Skip to main content
 

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

Author: Xiaoyang Last Modified: 2024-09-12

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?

return multiple lookup values separate by comma

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)
'Updateby Extendoffice
    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:

enter a formula to return multiple lookup values separate by comma

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 offers over 300 advanced features to streamline complex tasks, boosting creativity and efficiency. Enhanced with AI capabilities, Kutools automates tasks with precision, making data management effortless. Detailed information of Kutools for Excel...         Free trial...

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 > Merge & Split > Advanced Combine Rows, see screenshot:

click Advanced Combine Rows feature of kutools

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:

 click Primary Key that you want to combine based on

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:

choose one separator to separate the combined values

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:

original data arrow right return multiple values separate by comma

Download and free trial Kutools for Excel Now !

Best Office Productivity Tools

🤖 Kutools AI Aide: Revolutionize data analysis based on: Intelligent Execution   |  Generate Code  |  Create Custom Formulas  |  Analyze Data and Generate Charts  |  Invoke Kutools Functions
Popular Features: Find, Highlight or Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns  |  Move Columns  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolsets12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!