You could use
- a regexp to parse out all the non mathematical operator portions
- then
Evaluate
all these string sections
It probably will need finessing for complicated strings, but its a good start
Updated for more complex matches
code
Sub ParseEm()
Dim strIn As String
Dim strNew As String
Dim strCon As String
Dim lngCnt As Long
Dim objRegex As Object
Dim objRegMC As Object
Dim objRegM As Object
strCon = "|"
Set objRegex = CreateObject("vbscript.regexp")
With objRegex
.Pattern = "[^=/+/\/-/*\^]+"
.Global = True
strIn = [a1].Formula
If .test(strIn) Then
Set objRegMC = .Execute(strIn)
For Each objRegM In objRegMC
strNew = Evaluate(CStr(objRegM))
If objRegM.Length >= Len(strNew) Then
Mid$(strIn, objRegM.firstindex + 1 + lngCnt, objRegM.Length) = strNew & Application.Rept(strCon, objRegM.Length - Len(strNew))
Else
strIn = Left$(strIn, objRegM.firstindex + lngCnt) & strNew & Right$(strIn, Len(strIn) - objRegM.firstindex - objRegM.Length - lngCnt - 1)
lngCnt = lngCnt + Len(strNew) - objRegM.Length
End If
Next
strIn = Replace(strIn, strCon, vbNullString)
MsgBox strIn
Else
MsgBox "sorry, no matches"
End If
End With
End Sub