Public Sub Tinhgiatribieuthuc()
On Error Resume Next
Dim strText As String, congthuc As String
Dim Value1 As Double
Dim i As Integer
strText = ActiveCell.Text
For i = 1 To Len(strText)
Select Case Asc(Mid(strText, Len(strText) - i + 1, 1))
Case Is = 48, Is = 49, Is = 50, Is = 51, Is = 52, Is = 53, Is = 54, Is = 55, Is = 56, Is = 57, _
Is = 43, Is = 45, Is = 42, Is = 47, Is = 40, Is = 41, Is = 91, Is = 93, Is = 32, Is = 46
congthuc = Right(strText, i)
Case Else
Exit For
End Select
Next i
[COLOR=darkgreen]'Thay [ bang ( va ] bang )[/COLOR]
congthuc = Replace(congthuc, "[", "(")
congthuc = Replace(congthuc, "]", ")")
congthuc = Trim(congthuc)
Value1 = Evaluate(congthuc)
Value1 = Format(Value1, ActiveCell.NumberFormat)
ActiveCell.FormulaR1C1 = strText & " = " & Value1
[COLOR=darkgreen]'Tim ky tu "=" de lam cho ket qua co mau do[/COLOR]
For i = Len(ActiveCell.Text) To 1 Step -1
If Mid(ActiveCell.Text, i, 1) = "=" Then Exit For
Next i
With ActiveCell.Characters(Start:=1, Length:=i).Font
.ColorIndex = xlAutomatic
End With
With ActiveCell.Characters(Start:=i + 1, Length:=Len(ActiveCell.Text) - i).Font
.ColorIndex = 3
End With
End Sub