Private Sub Worksheet_Change(ByVal Target As Range)
Dim R As Range, Rng As Range
On Error Resume Next
Application.EnableEvents = False
Set R = Intersect(Target, Columns(2))
If R Is Nothing Then
Else
For Each Rng In R
Rng.Offset(, 1) = JiSuan(Rng.Text)
Next
End If
Set R = Intersect(Target, Columns(3))
Set Rng = Nothing
If R Is Nothing Then
Else
Set Rng = Columns(3).Find("sum(", , , xlPart, xlByColumns, xlNext, False, , False)
If Rng Is Nothing Then
Columns(5).Replace "合计", ""
Else
Rng.Offset(, 2) = "合计"
End If
End If
Application.EnableEvents = True
End Sub
Function JiSuan(Str As String) As Double
On Error Resume Next
For I = 1 To Len(Str)
S = Mid(Str, I, 1)
If S Like "[0-9()+-/*]" Then S1 = S1 & S
Next
If Str <> "" Then
JiSuan = Evaluate(S1)
Else
JiSuan = ""
End If
End Function
代码放到对应工作表中