How to lookup multiple values based on multiple criteria in one cell?

excelvbanoob420

New Member
Joined
Oct 5, 2022
Messages
15
Office Version
  1. 365
Platform
  1. Windows
Hello,

I need help for you guys for the following problem. I want to lookup multiple values based on multiple criteria in one cell. Below is the sample input and expected output:

Input Table 1:

IINPUTCOLUMN
FJ-SJ-0000-0101
FJ-RJ-0000
FJ-SJ-0000-0112
FJ-SJ-0000-0113
FJ-SJ-0000-0114
FJ-RJ-0001
FJ-SJ-0000-0115
FJ-RJ-0002
FJ-SJ-0000-0116
FJ-SJ-0000-0117

Input Table 2 (Lookup Table):

LookupTable Column1LookupTable Column2
FJ-SJ-0000-0101Valid P/N
FJ-SJ-0000-0112Valid P/N
FJ-SJ-0000-0113InValid P/N
FJ-SJ-0000-0114Valid P/N
FJ-SJ-0000-0116InValid P/N


OUTPUT (The lookup output expected is in OUTPUT COLUMN):

IINPUTCOLUMNOUTPUTCOLUMN
FJ-SJ-0000-0101
FJ-RJ-0000
Valid P/N
N/A
FJ-SJ-0000-0112
FJ-SJ-0000-0113
FJ-SJ-0000-0114
Valid P/N
InValid P/N
Valid P/N
FJ-RJ-0001
FJ-SJ-0000-0115
FJ-RJ-0002
FJ-SJ-0000-0116
FJ-SJ-0000-0117
N/A
N/A
N/A
InValid P/N
N/A

Thanks in advance for the help.
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Are Table 1 and Table 2 on the same sheet? If so, what ranges do the two tables occupy? It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshots (not pictures) of the tables. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing'
and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
 
Upvote 0
Are Table 1 and Table 2 on the same sheet? If so, what ranges do the two tables occupy? It would be easier to help if you could use the XL2BB add-in (icon in the menu) to attach screenshots (not pictures) of the tables. Alternately, you could upload a copy of your file to a free site such as www.box.com or www.dropbox.com. Once you do that, mark it for 'Sharing'
and you will be given a link to the file that you can post here. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary).
Hello,

Here is the snapshot from XL2BB add in:

Sample Workbook.xlsx
ABCDEFGHIJK
1IINPUTCOLUMNOUTPUTCOLUMNLookupTable Column1LookupTable Column2
2FJ-SJ-0000-0101 FJ-RJ-0000Valid P/N N/AFJ-SJ-0000-0101Valid P/N
3FJ-SJ-0000-0112 FJ-SJ-0000-0113 FJ-SJ-0000-0114Valid P/N InValid P/N Valid P/NFJ-SJ-0000-0112Valid P/N
4FJ-RJ-0001 FJ-SJ-0000-0115 FJ-RJ-0002 FJ-SJ-0000-0116 FJ-SJ-0000-0117N/A N/A N/A InValid P/N N/AFJ-SJ-0000-0113InValid P/N
5FJ-SJ-0000-0114Valid P/N
6FJ-SJ-0000-0116InValid P/N
7
8
9
10
11
Sheet1



Column A is the column of values that I want to lookup. Column J and K is the lookup table.
Intent here is lookup Column A values by matching in Column J and pulling the Column K values as output in Column B.
Hopefully the snapshot is clearer than my description. If my column A had single values in each cell I could just use Vlookup but since each cell in column A contains multiple values, I dont know how to go about looking up these values.
Any help is greatly appreciated!
 
Upvote 0
Try:
VBA Code:
Sub CompareData()
    Application.ScreenUpdating = False
    Dim i As Long, ii As Long, v As Variant, splitVal As Variant, fnd As Range
    v = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value
    For i = LBound(v) To UBound(v)
        splitVal = Split(v(i, 1), Chr(10))
        For ii = LBound(splitVal) To UBound(splitVal)
            Set fnd = Range("J:J").Find(splitVal(ii), LookIn:=xlValues, lookat:=xlWhole)
            If Not fnd Is Nothing Then
                If Range("B" & i + 1) = "" Then
                    Range("B" & i + 1) = fnd.Offset(, 1)
                Else
                    Range("B" & i + 1) = Range("B" & i + 1) & Chr(10) & fnd.Offset(, 1)
                End If
            Else
                If Range("B" & i + 1) = "" Then
                    Range("B" & i + 1) = "N/A"
                Else
                    Range("B" & i + 1) = Range("B" & i + 1) & Chr(10) & "N/A"
                End If
            End If
        Next ii
    Next i
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Try:
VBA Code:
Sub CompareData()
    Application.ScreenUpdating = False
    Dim i As Long, ii As Long, v As Variant, splitVal As Variant, fnd As Range
    v = Range("A2", Range("A" & Rows.Count).End(xlUp)).Value
    For i = LBound(v) To UBound(v)
        splitVal = Split(v(i, 1), Chr(10))
        For ii = LBound(splitVal) To UBound(splitVal)
            Set fnd = Range("J:J").Find(splitVal(ii), LookIn:=xlValues, lookat:=xlWhole)
            If Not fnd Is Nothing Then
                If Range("B" & i + 1) = "" Then
                    Range("B" & i + 1) = fnd.Offset(, 1)
                Else
                    Range("B" & i + 1) = Range("B" & i + 1) & Chr(10) & fnd.Offset(, 1)
                End If
            Else
                If Range("B" & i + 1) = "" Then
                    Range("B" & i + 1) = "N/A"
                Else
                    Range("B" & i + 1) = Range("B" & i + 1) & Chr(10) & "N/A"
                End If
            End If
        Next ii
    Next i
    Application.ScreenUpdating = True
End Sub
Thank you!
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top