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: 21

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
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,214,813
Messages
6,121,706
Members
449,048
Latest member
81jamesacct

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