2014年10月29日 星期三

Excel VBA RegExp Function

Function reg(str As String, pattern As String)
    Set regEx = CreateObject("VBScript.RegExp")
    regEx.pattern = pattern
    regEx.Global = True
    regEx.IgnoreCase = True
    Set Matches = regEx.Execute(str)
   
    If Matches.Count = 0 Then
        reg = "Not Found"
    Else
        reg = Matches(0).Value
    End If
   
End Function

=CONCATENATE("CLM-",reg(B2, "\d\d\d"))

沒有留言:

張貼留言