Multiple lookup from single cell

Ucubia

Board Regular
Joined
Mar 17, 2010
Messages
88
Hi,

I have been given some Excel data whereupon a cell will contain multiple asset tags separated by a comma.

Is it possible to perform a formula "lookup" of some description to return the item associated with the asset tag from another sheet and also separated with a comma

For example B2 contains tag 1047, 1382, 1755

In the Product sheet:
1047 Chair
1382 Table
1755 Book

The desired result being B2 cell 1047,1382,1755 and cell C2 resulting in Chair, Table, Book

Many thanks in advance

Ian
 
For those not running a version of Excel that includes the worksheet functions that Eric uses, here's a UDF that works.
Book1
BCDEFG
1Asset TagsAssetsAsset TagAsset
21047, 1382, 1755Chair, Table, Book1600locker
31382, 1047, 9000Table, Chair, N/A1755Book
41600, 9000, 1382locker, N/A, Table2022Gloves
51047Chair
61382Table
Sheet1
Cell Formulas
RangeFormula
C2:C4C2=GetAsset(B2,$F$2:$G$6)

VBA Code:
Function GetAsset(S As String, lkupRng As Range) As String
Dim V As Variant, i As Long, X As Variant
V = Split(S, ", ")
For i = LBound(V) To UBound(V)
    On Error Resume Next
    X = Application.VLookup(CLng(V(i)), Range(lkupRng.Address), 2, False)
    On Error GoTo 0
    If Not IsError(X) Then
        GetAsset = GetAsset & ", " & X
    Else
        GetAsset = GetAsset & ", " & "N/A"
    End If
Next i
GetAsset = Mid(GetAsset, 3, Len(GetAsset))
End Function
Hi Joe,

Does this code work when the reference points to a different sheet? In the example the lookup data is on the same page, but I am wondering if instead of $F$2:$G$6 something like File!$F$2:$G$6 will work or will I need additional code - I have tried but get a "N/A" when I know there will be an actual value.

Apologies coding is not something I do regularly and by that I mean "only in dire emergency"

Thanks

regards, Ian
 
Upvote 0

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Here's a modification to allow for the lookup table being on a different sheet, in this example Sheet2.
Book1
AB
589, 20, 68Al, Ant, Mike
Sheet1
Cell Formulas
RangeFormula
B5B5=GetAsset(A5,Sheet2!$D$2:$E$4)


Book1
DE
1ValueName
289Al
368Mike
420Ant
Sheet2

VBA Code:
Function GetAsset(S As String, lkupRng As Range) As String
Dim V As Variant, i As Long, X As Variant
V = Split(S, ", ")
For i = LBound(V) To UBound(V)
    On Error Resume Next
    X = Application.VLookup(CLng(V(i)), Range("'" & lkupRng.Parent.Name & "'!" & lkupRng.Address), 2, False)
    On Error GoTo 0
    If Not IsError(X) Then
        GetAsset = GetAsset & ", " & X
    Else
        GetAsset = GetAsset & ", " & "N/A"
    End If
Next i
GetAsset = Mid(GetAsset, 3, Len(GetAsset))
End Function
 
Upvote 0
Here's a modification to allow for the lookup table being on a different sheet, in this example Sheet2.
Book1
AB
589, 20, 68Al, Ant, Mike
Sheet1
Cell Formulas
RangeFormula
B5B5=GetAsset(A5,Sheet2!$D$2:$E$4)


Book1
DE
1ValueName
289Al
368Mike
420Ant
Sheet2

VBA Code:
Function GetAsset(S As String, lkupRng As Range) As String
Dim V As Variant, i As Long, X As Variant
V = Split(S, ", ")
For i = LBound(V) To UBound(V)
    On Error Resume Next
    X = Application.VLookup(CLng(V(i)), Range("'" & lkupRng.Parent.Name & "'!" & lkupRng.Address), 2, False)
    On Error GoTo 0
    If Not IsError(X) Then
        GetAsset = GetAsset & ", " & X
    Else
        GetAsset = GetAsset & ", " & "N/A"
    End If
Next i
GetAsset = Mid(GetAsset, 3, Len(GetAsset))
End Function
Awesome!! Just absolutely awesome! Tested and works a treat! Thank you so much and equally I can use a similar approach for something else that has just dropped into the inbox.

Really appreciate your help and patience.
 
Upvote 0
Awesome!! Just absolutely awesome! Tested and works a treat! Thank you so much and equally I can use a similar approach for something else that has just dropped into the inbox.

Really appreciate your help and patience.
You are welcome - thanks for the reply.
 
Upvote 0
For those not running a version of Excel that includes the worksheet functions that Eric uses, here's a UDF that works.
Book1
BCDEFG
1Asset TagsAssetsAsset TagAsset
21047, 1382, 1755Chair, Table, Book1600locker
31382, 1047, 9000Table, Chair, N/A1755Book
41600, 9000, 1382locker, N/A, Table2022Gloves
51047Chair
61382Table
Sheet1
Cell Formulas
RangeFormula
C2:C4C2=GetAsset(B2,$F$2:$G$6)

VBA Code:
Function GetAsset(S As String, lkupRng As Range) As String
Dim V As Variant, i As Long, X As Variant
V = Split(S, ", ")
For i = LBound(V) To UBound(V)
    On Error Resume Next
    X = Application.VLookup(CLng(V(i)), Range(lkupRng.Address), 2, False)
    On Error GoTo 0
    If Not IsError(X) Then
        GetAsset = GetAsset & ", " & X
    Else
        GetAsset = GetAsset & ", " & "N/A"
    End If
Next i
GetAsset = Mid(GetAsset, 3, Len(GetAsset))
End Function
I used this, but the results produced nothing. Need help. I need to use the entire invoice number to reference the status.

image1.PNG
image2.PNG
 
Upvote 0
I used this, but the results produced nothing. Need help. I need to use the entire invoice number to reference the status.

View attachment 57747View attachment 57748
Please provide some additional information including a detailed description of what you want to do, some sample data using XL2BB and the desired result you want for the sample data.
 
Upvote 0
This one is not accepting the "-A" or the "-B" when I run this function...

Load Plan.xlsm
BC
238319549-B, 38319625-A, 38319612-A, 38327534-B, 38327521-A, , , ,
3
4Pick Ticket#P/T Status
538319549-BPick Pending
638319625-ALoad Pending
738319612-ALoad Pending
838327534-BPick Pending
938327521-APick Pending
Sheet1
Cell Formulas
RangeFormula
C2C2=GetInvoiceStatus(B2,B5:C9)


But when I remove the "-A" characters it works flawlessly.

Load Plan.xlsm
BC
1Pick Ticket#P/T Status
238319549, 38319625, 38319612, 38327534, 38327521Pick Pending, Load Pending, Load Pending, Pick Pending, Pick Pending
3
4Pick Ticket#P/T Status
538319549Pick Pending
638319625Load Pending
738319612Load Pending
838327534Pick Pending
938327521Pick Pending
Sheet1
Cell Formulas
RangeFormula
C2C2=GetInvoiceStatus(B2,B5:C9)


I need the "-A" in the both "Pick Ticket#."
 
Upvote 0
This one is not accepting the "-A" or the "-B" when I run this function...
The function was created in response to the OP which used numeric inputs to the single cell. Here's a modification that allows for text values in the single cell:
Book1
BC
238319549-B, 38319625-A, 38319612-A, 38327534-B, 38327521-APick Pending, Load Pending, Load Pending, Pick Pending, Pick Pending
3
4Pick Ticket#P/T Status
538319549-BPick Pending
638319625-ALoad Pending
738319612-ALoad Pending
838327534-BPick Pending
938327521-APick Pending
Sheet3
Cell Formulas
RangeFormula
C2C2=GetInvoiceStatus(B2,B5:C9)

VBA Code:
Function GetInvoiceStatus(S As String, lkupRng As Range) As String
Dim V As Variant, i As Long, X As Variant
V = Split(S, ", ")
For i = LBound(V) To UBound(V)
    On Error Resume Next
    X = Application.VLookup(V(i), Range("'" & lkupRng.Parent.Name & "'!" & lkupRng.Address), 2, False)
    On Error GoTo 0
    If Not IsError(X) Then
        GetInvoiceStatus = GetInvoiceStatus & ", " & X
    Else
        GetInvoiceStatus = GetInvoiceStatus & ", " & "N/A"
    End If
Next i
GetInvoiceStatus = Mid(GetInvoiceStatus, 3, Len(GetInvoiceStatus))
End Function
 
Upvote 0

Forum statistics

Threads
1,216,113
Messages
6,128,905
Members
449,478
Latest member
Davenil

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