walkinginheels24
New Member
- Joined
- Jun 28, 2019
- Messages
- 3
I am trying to find a macro so I can extract a period number from a string of text e.g. P01 20
I have been using the following macro that I found on here, that I have edited however I cannot figure out how to include the space (between P01 and 20) to be included in the pattern line
Function Period(sInp As String) As String()
Dim oRE As Object
Dim oMat As Object
Dim asOut() As String
Dim iMat As Long
Set oRE = CreateObject("vbscript.regexp")
With oRE
.Global = True
.IgnoreCase = False
.Pattern = "(\b([P]{1}\d{2})\b)|"
If .Test(sInp) Then
Set oMat = .Execute(sInp)
ReDim asOut(0 To oMat.Count)
For iMat = 0 To oMat.Count - 1
asOut(iMat) = oMat(iMat)
Next iMat
End If
End With
Period = asOut
End Function
I have been using the following macro that I found on here, that I have edited however I cannot figure out how to include the space (between P01 and 20) to be included in the pattern line
Function Period(sInp As String) As String()
Dim oRE As Object
Dim oMat As Object
Dim asOut() As String
Dim iMat As Long
Set oRE = CreateObject("vbscript.regexp")
With oRE
.Global = True
.IgnoreCase = False
.Pattern = "(\b([P]{1}\d{2})\b)|"
If .Test(sInp) Then
Set oMat = .Execute(sInp)
ReDim asOut(0 To oMat.Count)
For iMat = 0 To oMat.Count - 1
asOut(iMat) = oMat(iMat)
Next iMat
End If
End With
Period = asOut
End Function