How to VLOOKUP Multiple Values in One Cell in Excel (2 Easy Methods)

We have a dataset with salesperson Names and their selling Products. Our goal is to find the selling products of each salesperson.

dataset of vlookup multiple values in one cell

Method 1 – Using Formulas to Vlookup Multiple Values in One Cell in Excel

The TEXTJOIN function will be used for this method. The TEXTJOIN function allows you to join 2 or more strings together with each value separated by a delimiter.

The TEXTJOIN function is only available for Excel 2019 and Office 365.

The Basic Syntax of TEXTJOIN Function:

=TEXTJOIN(delimiter, ignore_empty, text1, [text2], …)

The delimiter will be a comma (“,”) to separate values in one cell.


1.1 The TEXTJOIN and IF Functions

The Basic Syntax:

=TEXTJOIN(", ",TRUE,IF(lookup_value=lookup_range,,finding_range,""))

Steps

  1. Enter the following formula in Cell F5:
=TEXTJOIN(", ",TRUE,IF(E5=B5:B13,C5:C13,""))

textjoin and if functions to vlookup multiple values in one cell

2. Press Enter.

result of vlookup multiple values in one cell

3. Drag the Fill Handle icon to fill in the remaining cells.

drag the fill handle to copy the formula

Breakdown of the Formula

We are using this breakdown only for the person “John”

IF(E5=B5:B13,C5:C13,"")

This function returns the following array:

{"Mobile";"";"";"TV";"";"Fridge";"";"Mobile";""}

TEXTJOIN(", ",TRUE,IF(E5=B5:B13,C5:C13,""))

The TEXTJOIN function will return the following result:

{Mobile, TV, Fridge, Mobile}

Read More: Excel VLOOKUP to Return Multiple Values in One Cell Separated by Comma


1.2 The TEXTJOIN and MATCH Functions (Without Duplicates)

STEPS

1. Enter the following formula in cell F5:

=TEXTJOIN(",", TRUE, IF(IFERROR(MATCH(C5:C13, IF(E5=B5:B13, C5:C13, ""), 0),"")=MATCH(ROW(C5:C13), ROW(C5:C13)), C5:C13, ""))

textjoin and match functions to vlookup multiple values in one cell

2. Press Enter.

result of textjoin and match functions

3. Drag the Fill Handle icon to fill in the remaining cells.

drag fill handle to copy values in one cell

Breakdown of the Formula

We are using this breakdown only for the person “John”

ROW(C5:C13)

It returns an array of {5;6;7;8;9;10;11;12;13}

MATCH(ROW(C5:C13), ROW(C5:C13))

It returns: {1;2;3;4;5;6;7;8;9}

IF(E5=B5:B13, C5:C13, "")

It returns: {"Mobile";"";"";"TV";"";"Fridge";"";"Mobile";""}

MATCH(C5:C13, IF(E5=B5:B13, C5:C13, "")

This function returns: {8;8;7;9;7;7;7;8;7}

IFERROR(MATCH(C5:C13, IF(E5=B5:B13, C5:C13, ""), 0),"")

   It returns: {1;1;"";4;"";6;"";1;""}

IF(IFERROR(MATCH(C5:C13, IF(E5=B5:B13, C5:C13, ""), 0),"")=MATCH(ROW(C5:C13), ROW(C5:C13)), C5:C13, "")

It returns: {"Mobile";"";"";"TV";"";"Fridge";"";"";""}

TEXTJOIN(",", TRUE, IF(IFERROR(MATCH(C5:C13, IF(E5=B5:B13, C5:C13, ""), 0),"")=MATCH(ROW(C5:C13), ROW(C5:C13)), C5:C13, ""))

The final output will be Mobile, TV, Fridge.

Read More: How to Use VLOOKUP Function on Multiple Rows in Excel


1.3 The TEXTJOIN and UNIQUE Functions (Without Duplicates)

The Basic Syntax of UNIQUE Function:

=UNIQUE (array, [by_col], [exactly_once])

array – Range or array from which to extract unique values.

by_col – [optional] How to compare and extract. By row = FALSE (default); by column = TRUE.

exactly_once – [optional] TRUE = values that occur once, FALSE= all unique values (default)

STEPS

1. Enter the following formula in cell F5:

=TEXTJOIN(", ",TRUE,UNIQUE(IF(E5=B5:B13,C5:C13,"")))

textjoin and unique functions to lookup values

2.Press Enter.

textjoin and unique function result

3. Drag the Fill Handle icon to fill in the remaining cells.

drag the fill handle to copy the formula

Breakdown of the Formula

We are using this breakdown only for the person “John”

➤ IF(E5=B5:B13,C5:C13,"")

    It returns {"Mobile";"";"";"TV";"";"Fridge";"";"Mobile";""}

➤ UNIQUE(IF(E5=B5:B13,C5:C13,""))

It returns {"Mobile";"";"TV";"Fridge"}

TEXTJOIN(", ",TRUE,UNIQUE(IF(E5=B5:B13,C5:C13,"")))

   Final result Mobile,TV,Fridge

Read More: How to Vlookup and Return Multiple Values in Drop Down List


Method 2 – Using VBA Codes to Vlookup Multiple Values in One Cell

2.1 VBA Codes Multiple Values in One Cell

STEPS

1. Press Alt+F11 to open Visual Basic Editor.

2. Click on Insert > Module.

insert module for VBA editor

3. Enter the following code:

Function MultipleValues(work_range As Range, criteria As Variant, merge_range As Range, Optional Separator As String = ",") As Variant
Dim outcome As String
On Error Resume Next
If work_range.Count <> merge_range.Count Then
MultipleValues = CVErr(xlErrRef)
Exit Function
End If
For i = 1 To work_range.Count
If work_range.Cells(i).Value = criteria Then
outcome = outcome & Separator & merge_range.Cells(i).Value
End If
Next i
If outcome <> "" Then
outcome = VBA.Mid(outcome, VBA.Len(Separator) + 1)
End If
MultipleValues = outcome
Exit Function
End Function

4. Go to your worksheet and enter the following formula in Cell F5:

=MultipleValues(B5:B13,E5,C5:C13,",")

user defined function to vlookup multiple values in one cell

5. Press ENTER.

result of the vba codes

6. Drag the Fill Handle icon to fill in the remaining cells.

drag the fill handle to copy

Read More: VLOOKUP to Return Multiple Values Horizontally in Excel


2.2 VBA Codes to LOOKUP Multiple Values in One Cell (Without Duplicates)

STEPS

1. Press Alt+F11 to open Visual Basic Editor.

2. Click on Insert > Module.

3. Enter the following code:

Function ValuesNoDup(target As String, search_range As Range, ColumnNumber As Integer)
Dim i As Long
Dim outcome As String
For i = 1 To search_range.Columns(1).Cells.Count
If search_range.Cells(i, 1) = target Then
For J = 1 To i - 1
If search_range.Cells(J, 1) = target Then
If search_range.Cells(J, ColumnNumber) = search_range.Cells(i, ColumnNumber) Then
GoTo Skip
End If
End If
Next J
outcome = outcome & " " & search_range.Cells(i, ColumnNumber) & ","
Skip:
End If
Next i
ValuesNoDup = Left(outcome, Len(outcome) - 1)
End Function

4. The Microsoft Visual Basic for Applications window will open. Click Tools > References. From the References – VBAProject dialog box, check the Microsoft Scripting Runtime option in the Available References list box. Click OK.

select microsoft scripting runtime

5. Go to the worksheet and enter the following formula in Cell F5:

=ValuesNoDup(E5,B5:B13,2)

2 is the column number of the dataset.

vba codes to vlookup multiple values in one cell without duplicates

6. Press Enter.

result of the vba code

7. Drag the Fill Handle icon to fill in the remaining cells.

drag the fill handle to copy the formula


Download Practice Workbook


Related Articles


<< Go Back to VLOOKUP Multiple Values | Excel VLOOKUP Function | Excel Functions | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
A.N.M. Mohaimen Shanto
A.N.M. Mohaimen Shanto

A.N.M. Mohaimen Shanto, a B.Sc. in Computer Science and Engineering from Daffodil International University, boasts two years of experience as a Project Manager at Exceldemy. He authored 90+ articles and led teams as a Team Leader, meticulously reviewing over a thousand articles. Currently, he focuses on enhancing article quality. His passion lies in Excel VBA, Data Science, and SEO, where he enjoys simplifying complex ideas to facilitate learning and growth. His journey mirrors Exceldemy's dedication to excellence and... Read Full Bio

2 Comments
  1. Awesome tutorial. I’m always forgetting how to find and add multiple data points to one cell, especially when I have to create a specialized list using our directory of 8K employees. I have now downloaded the file and saved the formulas for quick reference. Thank you!

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo