
Originally Posted by
daboho
If in a1= "pattern is 111-123456 and pattern 444-123456"
The first my asking after use my udf
I want i B1 = 111-123456 444-123456
Second my asking
After use udf B1=111-123456 and 444-123456
Third my asking
After use UDF
In B1= 444-123456 ,C1=111-123456
Thank before
1) =aa(A1,"\d{3}-\d{4}")
2) =aa(A1,"\d{3}-\d{4}",,"and")
3) =IFERROR(aa($A1,"\d{3}-\d{4}",COLUMN(A1)),"") then fill right
Function aa(ByVal txt As String, myPtn As String, Optional ref As Long, Optional joinStr As String)
Dim m As Object
With CreateObject("VBScript.RegExp")
.Global = True
.Pattern = myPtn
If Len(joinStr) Then
For Each m In .Execute(txt)
aa = aa & " " & joinStr & " " & m.Value
Next
aa = Application.Trim(Mid$(aa, Len(joinStr) + 2))
Else
If ref = 0 Then ref = 1
aa = .Execute(txt)(ref - 1)
End If
End With
End Function
Bookmarks