How can i extract excel functions (only their names) from a string in visual basic?
For example i have: Sin(B6)*Sum(A2:A4) So i want to find a way to have "Sin" and "Sum" from this.
Note: I already have a code to extract cell addresses, it might give you a hint to help me out.
Thank you.
Dim result As Object
Dim testExpression As String
Dim objRegEx As Object
Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.IgnoreCase = True
objRegEx.Global = True
objRegEx.Pattern = """.*""" ' remove expressions
testExpression = Mystring
testExpression = objRegEx.Replace(testExpression, "")
objRegEx.Pattern = "(([A-Z])+(\d)+)" 'grab the address
Dim i As Long
Dim k As Long
If objRegEx.test(testExpression) Then
Set result = objRegEx.Execute(testExpression)
If result.Count > 0 Then
For Each Match In result
k = Len(Match.value)
i = 1
Do Until (i > k) Or (IsNumeric(Mid$(Match.value, i, 1)))
i = i + 1
Loop
Debug.Print Match.value
Next Match
End if