I've found many things online that show me how to create the function and how to implement it, but nothing is helping me figure out why it won't accept the function's name.
I opened the Visual Basic section under developer. I've entered my code and I assume that is it? Ctrl + S only makes me save the sheet, not the code.
The purpose of my code is to take a string and remove the first 7 characters, one of which will be a ; and the following 6 will be random numbers. I have some more fixing to do, such as removing 4 random characters from the end, but I wanted to test it out first.
Here is my code:
Function simpleCellRegex(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 = "^[;][0-9]{6}"
If strPattern <> "" Then
strInput = Myrange.Value
strReplace = ""
With regEx
.Global = True
.MultiLine = True
.IgnoreCase = False
.Pattern = strPattern
End With
If regEx.test(strInput) Then
simpleCellRegex = regEx.Replace(strInput, strReplace)
Else
simpleCellRegex = "Not matched"
End If
End If
End Function
I'm not sure if there is a step that I am missing that will allow excel to accept my code.
Thanks for any help!