Lookup and match multiple values separated by commas in a cell and produce matched value

abdulrahim845

New Member
Joined
Mar 13, 2023
Messages
18
Office Version
  1. 2016
Platform
  1. Windows
C2:C7 has single non-sequential numbers and B2:B7 has multiple numbers separated by commas in each cell. I want to match the C2 numbers in B2:B7 and get the output of the corresponding matching number in D2. Can anyone help me formulate this? Thanks
 

Attachments

  • Matched Values.JPG
    Matched Values.JPG
    71.6 KB · Views: 25

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
It would greatly help if you used XL2BB to show your sample data and expected result(s).
 
Upvote 0
C2:C7 has single non-sequential numbers and B2:B7 has multiple numbers separated by commas in each cell. I want to match the C2 numbers in B2:B7 and get the output of the corresponding matching number in D2. Can anyone help me formulate this? Thanks

It would greatly help if you used XL2BB to show your sample data and expected result(s).
Match Result.xlsx
BCD
1Non-Sequential ValuesValuesMatched Result
2740023485209026664278135, 786714215335, 884984185218, 884949627647026664278135
3029695323003716184544086, 089238300212, 342192107809, 342192107748, 892383002128, 611102105656, 015568971242, 781163724247892383002128
4029695323010660048001959, 622013297958, 078433272189, 885137765271, 626211276968, 653801183535, 799360746849653801183535
5026664278135622013297965, 069408137190, 740023485209, 660048001966, 626211276951740023485209
6653801183535029695323010029695323010
7892383002128029695323003, 786714526790029695323003
Sheet1
 
Upvote 0
Are your instruction in reverse? Column C has numbers separated by a comma. Column B has single numbers.
What determines the results in column D?
 
Upvote 0
Are your instruction in reverse? Column C has numbers separated by a comma. Column B has single numbers.
What determines the results in column D?
C2 has multiple numbers, from these numbers 1 number must be matched from B2:B7. I want to match that matching number and get output in D2
 
Upvote 0
Maybe this?

Code:
Sub VinC()
Dim ary() As String, i As Long, lr As Long, u As Long, w As Variant
lr = Cells(Rows.Count, "B").End(xlUp).Row

For i = 2 To lr
 ary() = Split(Cells(i, "C"), ", ")
  For u = LBound(ary) To UBound(ary)
   If IsNumeric(Application.Match(ary(u), Range("B2:B" & lr), 0)) Then
    Cells(i, "E") = Right("0" & ary(u), 12)
    GoTo found
    Else
   End If
  Next u
found: Next i
End Sub

I put my results in the E column just to compare. Change accordingly
 
Upvote 0
Thanks for the help. Execute the first time now It gets stuck at the "Else:" argument.
 

Attachments

  • Capture.JPG
    Capture.JPG
    101.8 KB · Views: 15
Upvote 0
Looks like you put a stop in the code.

Book1
BCDE
1Non-Sequential ValuesValuesMatched Result
2740023485209026664278135, 786714215335, 884984185218, 884949627647026664278135026664278135
3029695323003716184544086, 089238300212, 342192107809, 342192107748, 892383002128, 611102105656, 015568971242, 781163724247892383002128892383002128
4029695323010660048001959, 622013297958, 078433272189, 885137765271, 626211276968, 653801183535, 799360746849653801183535653801183535
5026664278135622013297965, 069408137190, 740023485209, 660048001966, 626211276951740023485209740023485209
6653801183535029695323010029695323010029695323010
7892383002128029695323003, 786714526790029695323003029695323003
Sheet1
 
Upvote 0
I am using VBA for the first time. Maybe I did some mistake. Now I re-apply and it runs smoothly, but it didn't get all values. What may the error be?

Match Result.xlsm
BCDE
1Non-Sequential ValuesValuesMatched Result
2740023485209026664278135, 786714215335, 884984185218, 88494962764702666427813526664278135
3029695323003716184544086, 089238300212, 342192107809, 342192107748, 892383002128, 611102105656, 015568971242, 781163724247892383002128
4029695323010660048001959, 622013297958, 078433272189, 885137765271, 626211276968, 653801183535, 799360746849653801183535
5026664278135622013297965, 069408137190, 740023485209, 660048001966, 626211276951740023485209
665380118353502969532301002969532301029695323010
7892383002128029695323003, 78671452679002969532300329695323003
Sheet1
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,149
Members
453,021
Latest member
Justyna P

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