I think this will do what you want - It can only cope with one lot of multiple (( & )) brackets
It only looks at cell A1 & displays the result in a message box
Code can be modified to run down a column & place the result into another column
Sub ConvertTxtToFormula()
Dim i4Cnt As Integer
Dim sCellTxt As String
Dim sParam As String
Dim sChar As String
Dim sFormula As String
Dim iPos(4) As Integer
sCellTxt = Range("a1").Value
For i4Cnt = 1 To Len(sCellTxt) Step 1
sChar = Mid(sCellTxt, i4Cnt, 1)
Select Case sChar
Case "("
If i4Cnt = 1 Then
iPos(0) = 1
iPos(1) = i4Cnt
Else
iPos(1) = i4Cnt + 1
End If
Case ")"
If Mid(sCellTxt, i4Cnt - 1, 2) = "))" Then
iPos(1) = i4Cnt - 1
End If
iPos(0) = (i4Cnt) - iPos(1)
Case "-", "+,", "/", "*", "^"
iPos(1) = i4Cnt
iPos(0) = 1
End Select
If iPos(0) > 0 Then
sParam = Mid(sCellTxt, iPos(1), iPos(0))
iPos(0) = 0
Select Case Right(sFormula, 1)
Case "-", "+,", "/", "*", "^", ""
sFormula = sFormula & sParam
Case Else
Select Case sParam
Case "-", "+,", "/", "*", "^"
sFormula = sFormula & sParam
Case Else
sFormula = sFormula & "*" & sParam
End Select
If sParam = ")" Then
sParam = Trim(Mid(sCellTxt, i4Cnt + 1))
Select Case sParam
Case "-", "+,", "/", "*", "^"
sFormula = sFormula & sParam
Case Else
sFormula = sFormula & "*" & sParam
End Select
Exit For
End If
End Select
End If
Next i4Cnt
MsgBox sFormula
End Sub
Bookmarks