It looks like the same code can appear several times in one cell? In such a case, do you want the function to return it multiple times or should it only return a list of unique values?
This code will return all matches regardless but would need amending to return unique values only:
Function MatchNumbers(sText As String, Optional sMissing As String = "Not found") As String
Static myRegEx As Object
Dim all_matches
Dim match
If myRegEx Is Nothing Then Set myRegEx = CreateObject("vbscript.regexp")
With myRegEx
.Global = True
.Pattern = "(C00\d+)"
Set all_matches = .Execute(sText)
For Each match In all_matches
MatchNumbers = MatchNumbers & "," & match
Next
End With
If Len(MatchNumbers) <> 0 Then
MatchNumbers = Mid$(MatchNumbers, 2)
Else
MatchNumbers = sMissing
End If
End Function
You need to add the code to a normal module and then call it from a cell:
=MatchNumbers(J2)
for instance.
Bookmarks