I have two functions to extract an exact sequence of characters, but I can not join the functions.
Would it be possible to put them together?
I tried some ways, but it always returns me error.
Public Function ExtraiNúmCNJ(Texto As Variant) As String
Application.Volatile True
With CreateObject("VBScript.Regexp")
.Global = False
.Pattern = "\d{7}\s*\.?\s*\d{2}\s*\.?\s*\d{4}\s*\.?\s*\d\s*\.?\s*\d{2}\s*\.?\s*\d{4}"
If .test(Texto) Then
ExtraiNúmCNJ = .Execute(Texto)(0)
.Global = True:
.Pattern = "\D"
ExtraiNúmCNJ = Format(.Replace(ExtraiNúmCNJ, ""), "0000000\-00\.0000\.0\.00\.0000")
End If
End With
End Function
Public Function ExtraiNúmAntigo(Texto As Variant) As String
Application.Volatile True
With CreateObject("VBScript.Regexp")
.Global = False
.Pattern = "\d{4}\s*\.?\s*\d{2}\s*\.?\s*\d{6}\s*\.?\s*\d{1}"
If .test(Texto) Then
ExtraiNúmAntigo = .Execute(Texto)(0)
.Global = True:
.Pattern = "\D"
ExtraiNúmAntigo = Format(.Replace(ExtraiNúmAntigo, ""), "0000\.00\.000000\.0")
End If
End With
End Function
I currently use it as follows:
I'm trying to leave with only one function by pulling the two types of numbers.