I'm trying to create my own VBA Function based on the one in step two at this link. How to use Regular Expressions (Regex) in Microsoft Excel both in-cell and loops
However, I get a #NAME error. Where am I going wrong here? I've tested my RegEx on https://regex101.com.
Function extractGroupName(Myrange As Range) As String
Dim regEx As New RegExp
Dim strPattern As String
Dim strInput As String
Dim strReplace As String
Dim strOutput As String
strPattern = "^.*Name:(.*);Id"
If strPattern <> "" Then
strInput = Myrange.Value
strReplace = "$1"
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regEx.Test(strInput) Then
extractGroupName = regEx.Replace(strInput, "$1")
Else
extractGroupName = "ERROR: NOT FOUND"
End If
End If
End Function