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

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
try this
VBA Code:
Sub wrc()
        Dim regex As Object
        Set regex = CreateObject("vbscript.regexp")
        Dim mc, s
        Dim k As Boolean
        Dim p As Long
        regex.Global = True
        regex.Pattern = "[0-9]+"
         
        For p = 2 To Range("B" & Rows.Count).End(xlUp).Row
            Set mc = regex.Execute(Range("B" & p).Value)
            
            On Error Resume Next
            
            For Each s In mc
                 k = WorksheetFunction.Match(CStr(Int(s)), Range("A:A"), 0)
                 If k = True Then
                    Range("C" & p).Value = s & "," & Range("C" & p).Value
                    k = False
                End If
            Next s
            
            On Error GoTo 0
        Next p
        
        
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
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